anon.crypto
Class MyRSASignature

java.lang.Object
  extended by anon.crypto.MyRSASignature
All Implemented Interfaces:
IMySignature, ISignatureCreationAlgorithm, ISignatureVerificationAlgorithm

public final class MyRSASignature
extends java.lang.Object
implements IMySignature

SHA1withRSA Signature as described in RFC 2437


Field Summary
private  org.bouncycastle.crypto.digests.SHA1Digest m_Digest
           
private  java.security.Key m_initKey
          The key with that this algorithm has been initialised.
private  org.bouncycastle.crypto.encodings.PKCS1Encoding m_SignatureAlgorithm
           
private static org.bouncycastle.asn1.x509.AlgorithmIdentifier ms_AlgID
           
private static org.bouncycastle.asn1.x509.AlgorithmIdentifier ms_identifier
           
 
Constructor Summary
MyRSASignature()
           
 
Method Summary
 byte[] decodeForXMLSignature(byte[] a_encodedSignature)
          Tries to decode a signature in a way as it would meet the W3C standard for RSA XML signature values.
 byte[] encodeForXMLSignature(byte[] a_signature)
          Encodes a signature in a way it meets the W3C standard for RSA XML signature values.
 org.bouncycastle.asn1.x509.AlgorithmIdentifier getIdentifier()
          Returns the algorithm identifier (RSA with SHA1).
 java.lang.String getXMLSignatureAlgorithmReference()
          Returns http://www.w3.org/2000/09/xmldsig#rsa-sha1.
 void initSign(IMyPrivateKey k)
          Initialises the algorithm for signing.
 void initVerify(IMyPublicKey k)
          Initialises the algorithm for verifying.
 byte[] sign(byte[] bytesToSign)
          Signs a message and returns the signature.
 byte[] signPlain(byte[] hash)
          Only does the signature calculation assuming that the input already is a hash
 boolean verify(byte[] a_message, byte[] a_signature)
          Tests if the signature of a specified message is valid.
 boolean verify(byte[] message, int message_offset, int message_len, byte[] sig, int signature_offset, int signature_len)
          Tests if the signature of a specified message is valid.
 boolean verifyPlain(byte[] hash, byte[] sig)
          Verifyes a signature for a given hash
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ms_identifier

private static final org.bouncycastle.asn1.x509.AlgorithmIdentifier ms_identifier

m_SignatureAlgorithm

private org.bouncycastle.crypto.encodings.PKCS1Encoding m_SignatureAlgorithm

m_initKey

private java.security.Key m_initKey
The key with that this algorithm has been initialised.


m_Digest

private org.bouncycastle.crypto.digests.SHA1Digest m_Digest

ms_AlgID

private static final org.bouncycastle.asn1.x509.AlgorithmIdentifier ms_AlgID
Constructor Detail

MyRSASignature

public MyRSASignature()
Method Detail

initVerify

public void initVerify(IMyPublicKey k)
                throws java.security.InvalidKeyException
Description copied from interface: IMySignature
Initialises the algorithm for verifying. This must be done before doing the verify operation. The general contract of this method is that it must check if the algorithm has previously been initialised with the given key. If yes the method does nothing to save resources.

Specified by:
initVerify in interface IMySignature
Parameters:
k - a public key
Throws:
java.security.InvalidKeyException - if the key is invalid

initSign

public void initSign(IMyPrivateKey k)
              throws java.security.InvalidKeyException
Description copied from interface: IMySignature
Initialises the algorithm for signing. This must be done before doing the sign operation. The general contract of this method is that it must check if the algorithm has previously been initialised with the given key. If yes the method does nothing to save resources.

Specified by:
initSign in interface IMySignature
Parameters:
k - a private key
Throws:
java.security.InvalidKeyException - if the key is invalid

verify

public boolean verify(byte[] a_message,
                      byte[] a_signature)
Description copied from interface: IMySignature
Tests if the signature of a specified message is valid.

Specified by:
verify in interface IMySignature
Specified by:
verify in interface ISignatureVerificationAlgorithm
Parameters:
a_message - a message
a_signature - a signature
Returns:
true if the signature of a specified message is valid; false otherwiese

verify

public boolean verify(byte[] message,
                      int message_offset,
                      int message_len,
                      byte[] sig,
                      int signature_offset,
                      int signature_len)
Description copied from interface: ISignatureVerificationAlgorithm
Tests if the signature of a specified message is valid.

Specified by:
verify in interface ISignatureVerificationAlgorithm
Parameters:
message - a message
message_offset - start of message
message_len - length of message
sig - a signature
signature_offset - start of signature
signature_len - length of signature
Returns:
true if the signature of a specified message is valid; false otherwiese

verifyPlain

public boolean verifyPlain(byte[] hash,
                           byte[] sig)
Verifyes a signature for a given hash


sign

public byte[] sign(byte[] bytesToSign)
Description copied from interface: IMySignature
Signs a message and returns the signature.

Specified by:
sign in interface IMySignature
Specified by:
sign in interface ISignatureCreationAlgorithm
Parameters:
bytesToSign - a message
Returns:
the signature that was created

signPlain

public byte[] signPlain(byte[] hash)
Only does the signature calculation assuming that the input already is a hash


getIdentifier

public org.bouncycastle.asn1.x509.AlgorithmIdentifier getIdentifier()
Returns the algorithm identifier (RSA with SHA1).

Specified by:
getIdentifier in interface ISignatureCreationAlgorithm
Specified by:
getIdentifier in interface ISignatureVerificationAlgorithm
Returns:
the algorithm identifier (RSA with SHA1)

encodeForXMLSignature

public byte[] encodeForXMLSignature(byte[] a_signature)
Encodes a signature in a way it meets the W3C standard for RSA XML signature values. Note: No further encoding has to be done!

Specified by:
encodeForXMLSignature in interface IMySignature
Specified by:
encodeForXMLSignature in interface ISignatureCreationAlgorithm
Parameters:
a_signature - an non-encoded signature
Returns:
the encoded signature in PKCS1 format or null if an error occured
See Also:
http://tools.ietf.org/html/rfc2437#section-8.1, http://www.w3.org/TR/xmldsig-core/#sec-PKCS1

decodeForXMLSignature

public byte[] decodeForXMLSignature(byte[] a_encodedSignature)
Tries to decode a signature in a way as it would meet the W3C standard for RSA XML signature values. Note: No further decoding has to be done!

Specified by:
decodeForXMLSignature in interface IMySignature
Specified by:
decodeForXMLSignature in interface ISignatureVerificationAlgorithm
Parameters:
a_encodedSignature - an encoded signature in PKCS1 format
Returns:
the decoded signature or null if an error occured
See Also:
http://tools.ietf.org/html/rfc2437#section-8.1, http://www.w3.org/TR/xmldsig-core/#sec-PKCS1

getXMLSignatureAlgorithmReference

public java.lang.String getXMLSignatureAlgorithmReference()
Returns http://www.w3.org/2000/09/xmldsig#rsa-sha1.

Specified by:
getXMLSignatureAlgorithmReference in interface IMySignature
Specified by:
getXMLSignatureAlgorithmReference in interface ISignatureCreationAlgorithm
Specified by:
getXMLSignatureAlgorithmReference in interface ISignatureVerificationAlgorithm
Returns:
http://www.w3.org/2000/09/xmldsig#rsa-sha1
See Also:
http://www.w3.org/TR/xmldsig-core/#sec-AlgID