Package totalcross.crypto.signature
Class Signature
- java.lang.Object
-
- totalcross.crypto.signature.Signature
-
- Direct Known Subclasses:
PKCS1Signature
public abstract class Signature extends java.lang.ObjectThis class provides the functionality of a signature algorithm for signing and verifying.
-
-
Field Summary
Fields Modifier and Type Field Description protected Keykeyprotected intoperationstatic intOPERATION_SIGNConstant used to initialize this signature algorithm to sign.static intOPERATION_VERIFYConstant used to initialize this signature algorithm to verify.
-
Constructor Summary
Constructors Constructor Description Signature()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voiddoReset()protected abstract byte[]doSign(byte[] data)protected abstract booleandoVerify(byte[] data, byte[] expected)abstract java.lang.StringgetAlgorithm()Returns the name of the signature algorithm.protected abstract booleanisKeySupported(Key key, int operation)voidreset(int operation, Key key)Initializes this message signature algorithm to sign or verify.byte[]sign()Finalizes the sign operation by processing all the accumulated input data and returning the result in a new buffer.java.lang.StringtoString()Returns the name of the algorithm.voidupdate(byte[] data)Updates the input data that will be processed by this signature algorithm.voidupdate(byte[] data, int start, int count)Updates the input data that will be processed by this signature algorithm.voidupdate(int data)Updates the input data that will be processed by this signature algorithm.booleanverify(byte[] signature)Finalizes the verify operation by processing all the accumulated input data and returning the signature comparison result.
-
-
-
Field Detail
-
operation
protected int operation
-
key
protected Key key
-
OPERATION_SIGN
public static final int OPERATION_SIGN
Constant used to initialize this signature algorithm to sign.- See Also:
- Constant Field Values
-
OPERATION_VERIFY
public static final int OPERATION_VERIFY
Constant used to initialize this signature algorithm to verify.- See Also:
- Constant Field Values
-
-
Method Detail
-
toString
public final java.lang.String toString()
Returns the name of the algorithm.- Overrides:
toStringin classjava.lang.Object- Returns:
- The name of the algorithm used.
-
reset
public final void reset(int operation, Key key) throws CryptoExceptionInitializes this message signature algorithm to sign or verify. Calling this method will also reset the input data buffer.- Parameters:
operation- The operation mode of this signature algorithm (OPERATION_SIGNorOPERATION_VERIFY).key- The key.- Throws:
CryptoException- If one or more initialization parameters are invalid or the signature algorithm fails to initialize with the given parameters.
-
update
public final void update(int data)
Updates the input data that will be processed by this signature algorithm. The data will be accumulated in an input buffer to be processed whensign()orverify(byte[])is finally called.- Parameters:
data- The input data.
-
update
public final void update(byte[] data)
Updates the input data that will be processed by this signature algorithm. The data will be accumulated in an input buffer to be processed whensign()orverify(byte[])is finally called.- Parameters:
data- The input data.
-
update
public final void update(byte[] data, int start, int count)Updates the input data that will be processed by this signature algorithm. The data will be accumulated in an input buffer to be processed whensign()orverify(byte[])is finally called.- Parameters:
data- The input data.start- The offset indatawhere the data starts.count- The input length.
-
sign
public byte[] sign() throws CryptoExceptionFinalizes the sign operation by processing all the accumulated input data and returning the result in a new buffer.- Returns:
- The signature in a new buffer.
- Throws:
CryptoException
-
verify
public boolean verify(byte[] signature) throws CryptoExceptionFinalizes the verify operation by processing all the accumulated input data and returning the signature comparison result.- Returns:
- the signature comparison result.
- Throws:
CryptoException
-
getAlgorithm
public abstract java.lang.String getAlgorithm()
Returns the name of the signature algorithm.- Returns:
- The name of the signature algorithm used.
-
isKeySupported
protected abstract boolean isKeySupported(Key key, int operation)
-
doReset
protected abstract void doReset() throws NoSuchAlgorithmException, CryptoException
-
doSign
protected abstract byte[] doSign(byte[] data) throws CryptoException- Throws:
CryptoException
-
doVerify
protected abstract boolean doVerify(byte[] data, byte[] expected) throws CryptoException- Throws:
CryptoException
-
-