anon.crypto
Class MyECDSASignature

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

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


Field Summary
(package private)  org.bouncycastle.crypto.digests.SHA1Digest m_digest
           
private  java.security.Key m_initKey
           
(package private)  org.bouncycastle.crypto.signers.ECDSASigner m_signatureAlgorithm
           
private static org.bouncycastle.asn1.x509.AlgorithmIdentifier ms_identifier
           
 
Constructor Summary
MyECDSASignature()
           
 
Method Summary
 byte[] decodeForXMLSignature(byte[] a_encodedSignature)
          Tries to decode a signature in a way as it would meet the W3C standard for XML signature values.
 byte[] encodeForXMLSignature(byte[] a_signature)
          Encodes a signature in a way it meets the W3C standard for XML signature values.
 org.bouncycastle.asn1.x509.AlgorithmIdentifier getIdentifier()
          Returns the algorithm identifier.
 java.lang.String getXMLSignatureAlgorithmReference()
          Returns a description of the the signature algorithm for XML signatures as defined in http://www.w3.org/TR/xmldsig-core/#sec-AlgID.
 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.
 boolean verify(byte[] a_message, byte[] a_signature)
          Tests if the signature of a specified message is valid.
 boolean verify(byte[] a_message, int message_offset, int message_len, byte[] a_signature, int signature_offset, int signature_len)
          Tests if the signature of a specified message is valid.
 
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_digest

org.bouncycastle.crypto.digests.SHA1Digest m_digest

m_signatureAlgorithm

org.bouncycastle.crypto.signers.ECDSASigner m_signatureAlgorithm

m_initKey

private java.security.Key m_initKey
Constructor Detail

MyECDSASignature

public MyECDSASignature()
Method Detail

encodeForXMLSignature

public byte[] encodeForXMLSignature(byte[] a_signature)
Description copied from interface: IMySignature
Encodes a signature in a way it meets the W3C standard for XML signature values. Without this encoding, XML signatures cannot be created by this algorithm.

Specified by:
encodeForXMLSignature in interface IMySignature
Specified by:
encodeForXMLSignature in interface ISignatureCreationAlgorithm
Parameters:
a_signature - an non-encoded signature
Returns:
the encoded signature or null if an error occured
See Also:
http://www.w3.org/TR/xmldsig-core/#sec-SignatureAlg

decodeForXMLSignature

public byte[] decodeForXMLSignature(byte[] a_encodedSignature)
Description copied from interface: IMySignature
Tries to decode a signature in a way as it would meet the W3C standard for XML signature values. Without this decoding, XML signatures cannot be verified by this algorithm.

Specified by:
decodeForXMLSignature in interface IMySignature
Specified by:
decodeForXMLSignature in interface ISignatureVerificationAlgorithm
Parameters:
a_encodedSignature - an encoded signature
Returns:
the decoded signature or null if an error occured
See Also:
http://www.w3.org/TR/xmldsig-core/#sec-SignatureAlg

getXMLSignatureAlgorithmReference

public java.lang.String getXMLSignatureAlgorithmReference()
Description copied from interface: IMySignature
Returns a description of the the signature algorithm for XML signatures as defined in http://www.w3.org/TR/xmldsig-core/#sec-AlgID. This description is optional, documents may be signed without it.

Specified by:
getXMLSignatureAlgorithmReference in interface IMySignature
Specified by:
getXMLSignatureAlgorithmReference in interface ISignatureCreationAlgorithm
Specified by:
getXMLSignatureAlgorithmReference in interface ISignatureVerificationAlgorithm
Returns:
http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1
See Also:
http://www.w3.org/TR/xmldsig-core/#sec-AlgID

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

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

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

verify

public boolean verify(byte[] a_message,
                      int message_offset,
                      int message_len,
                      byte[] a_signature,
                      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:
a_message - a message
message_offset - start of message
message_len - length of message
a_signature - 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

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

getIdentifier

public org.bouncycastle.asn1.x509.AlgorithmIdentifier getIdentifier()
Description copied from interface: ISignatureCreationAlgorithm
Returns the algorithm identifier.

Specified by:
getIdentifier in interface ISignatureCreationAlgorithm
Specified by:
getIdentifier in interface ISignatureVerificationAlgorithm
Returns:
the algorithm identifier