Class Signature
- Direct Known Subclasses:
OpenSSLSignature,OpenSSLSignatureRawRSA,SHA1withDSA_SignatureImpl
public abstract class Signature extends SignatureSpi
Signature is an engine class which is capable of creating and
verifying digital signatures, using different algorithms that have been
registered with the Security class.- See Also:
SignatureSpi
-
Field Summary
Fields Modifier and Type Field Description protected static intSIGNConstant that indicates that thisSignatureinstance has been initialized for signing.protected intstateRepresents the current state of thisSignature.protected static intUNINITIALIZEDConstant that indicates that thisSignatureinstance has not yet been initialized.protected static intVERIFYConstant that indicates that thisSignatureinstance has been initialized for verification.Fields inherited from class java.security.SignatureSpi
appRandom -
Constructor Summary
-
Method Summary
Modifier and Type Method Description Objectclone()Creates and returns a copy of thisObject.StringgetAlgorithm()Returns the name of the algorithm of thisSignature.static SignaturegetInstance(String algorithm)Returns a new instance ofSignaturethat utilizes the specified algorithm.static SignaturegetInstance(String algorithm, String provider)Returns a new instance ofSignaturethat utilizes the specified algorithm from the specified provider.static SignaturegetInstance(String algorithm, Provider provider)Returns a new instance ofSignaturethat utilizes the specified algorithm from the specified provider.ObjectgetParameter(String param)Deprecated.There is no generally accepted parameter naming convention.AlgorithmParametersgetParameters()Returns theAlgorithmParametersof thisSignatureinstance.ProvidergetProvider()Returns the provider associated with thisSignature.voidinitSign(PrivateKey privateKey)Initializes thisSignatureinstance for signing, using the private key of the identity whose signature is going to be generated.voidinitSign(PrivateKey privateKey, SecureRandom random)Initializes thisSignatureinstance for signing, using the private key of the identity whose signature is going to be generated and the specified source of randomness.voidinitVerify(Certificate certificate)Initializes thisSignatureinstance for signature verification, using the certificate of the identity whose signature is going to be verified.voidinitVerify(PublicKey publicKey)Initializes thisSignatureinstance for signature verification, using the public key of the identity whose signature is going to be verified.voidsetParameter(String param, Object value)Deprecated.UsesetParameter(AlgorithmParameterSpec)instead.voidsetParameter(AlgorithmParameterSpec params)Sets the specifiedAlgorithmParameterSpec.byte[]sign()Generates and returns the signature of all updated data.intsign(byte[] outbuf, int offset, int len)Generates and stores the signature of all updated data in the providedbyte[]at the specified position with the specified length.StringtoString()Returns a string containing a concise, human-readable description of thisSignatureincluding its algorithm and its state.voidupdate(byte b)Updates the data to be verified or to be signed, using the specifiedbyte.voidupdate(byte[] data)Updates the data to be verified or to be signed, using the specifiedbyte[].voidupdate(byte[] data, int off, int len)Updates the data to be verified or to be signed, using the givenbyte[], starting form the specified index for the specified length.voidupdate(ByteBuffer data)Updates the data to be verified or to be signed, using the specifiedByteBuffer.booleanverify(byte[] signature)Indicates whether the givensignaturecan be verified using the public key or a certificate of the signer.booleanverify(byte[] signature, int offset, int length)Indicates whether the givensignaturestarting at indexoffsetwithlengthbytes can be verified using the public key or a certificate of the signer.Methods inherited from class java.security.SignatureSpi
engineGetParameter, engineGetParameters, engineInitSign, engineInitSign, engineInitVerify, engineSetParameter, engineSetParameter, engineSign, engineSign, engineUpdate, engineUpdate, engineUpdate, engineVerify, engineVerify
-
Field Details
-
UNINITIALIZED
protected static final int UNINITIALIZEDConstant that indicates that thisSignatureinstance has not yet been initialized.- See Also:
- Constant Field Values
-
SIGN
protected static final int SIGNConstant that indicates that thisSignatureinstance has been initialized for signing.- See Also:
- Constant Field Values
-
VERIFY
protected static final int VERIFYConstant that indicates that thisSignatureinstance has been initialized for verification.- See Also:
- Constant Field Values
-
state
protected int stateRepresents the current state of thisSignature. The three possible states areUNINITIALIZED,SIGNorVERIFY.
-
-
Constructor Details
-
Signature
Constructs a new instance ofSignaturewith the name of the algorithm to use.- Parameters:
algorithm- the name of algorithm to use.
-
-
Method Details
-
getInstance
Returns a new instance ofSignaturethat utilizes the specified algorithm.- Parameters:
algorithm- the name of the algorithm to use.- Returns:
- a new instance of
Signaturethat utilizes the specified algorithm. - Throws:
NoSuchAlgorithmException- if the specified algorithm is not available.NullPointerException- ifalgorithmisnull.
-
getInstance
public static Signature getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderExceptionReturns a new instance ofSignaturethat utilizes the specified algorithm from the specified provider.- Parameters:
algorithm- the name of the algorithm to use.provider- the name of the provider.- Returns:
- a new instance of
Signaturethat utilizes the specified algorithm from the specified provider. - Throws:
NoSuchAlgorithmException- if the specified algorithm is not available.NoSuchProviderException- if the specified provider is not available.NullPointerException- ifalgorithmisnull.IllegalArgumentException- ifprovider == null || provider.isEmpty()
-
getInstance
public static Signature getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmExceptionReturns a new instance ofSignaturethat utilizes the specified algorithm from the specified provider.- Parameters:
algorithm- the name of the algorithm to use.provider- the security provider.- Returns:
- a new instance of
Signaturethat utilizes the specified algorithm from the specified provider. - Throws:
NoSuchAlgorithmException- if the specified algorithm is not available.NullPointerException- ifalgorithmisnull.IllegalArgumentException- ifprovider == null
-
getProvider
Returns the provider associated with thisSignature.- Returns:
- the provider associated with this
Signature.
-
getAlgorithm
Returns the name of the algorithm of thisSignature.- Returns:
- the name of the algorithm of this
Signature.
-
initVerify
Initializes thisSignatureinstance for signature verification, using the public key of the identity whose signature is going to be verified.- Parameters:
publicKey- the public key.- Throws:
InvalidKeyException- ifpublicKeyis not valid.
-
initVerify
Initializes thisSignatureinstance for signature verification, using the certificate of the identity whose signature is going to be verified.If the given certificate is an instance of
X509Certificateand has a key usage parameter that indicates, that this certificate is not to be used for signing, anInvalidKeyExceptionis thrown.- Parameters:
certificate- the certificate used to verify a signature.- Throws:
InvalidKeyException- if the publicKey in the certificate is not valid or not to be used for signing.
-
initSign
Initializes thisSignatureinstance for signing, using the private key of the identity whose signature is going to be generated.- Parameters:
privateKey- the private key.- Throws:
InvalidKeyException- ifprivateKeyis not valid.
-
initSign
Initializes thisSignatureinstance for signing, using the private key of the identity whose signature is going to be generated and the specified source of randomness.- Parameters:
privateKey- the private key.random- theSecureRandomto use.- Throws:
InvalidKeyException- ifprivateKeyis not valid.
-
sign
Generates and returns the signature of all updated data.This
Signatureinstance is reset to the state of its last initialization for signing and thus can be used for another signature from the same identity.- Returns:
- the signature of all updated data.
- Throws:
SignatureException- if thisSignatureinstance is not initialized properly.
-
sign
Generates and stores the signature of all updated data in the providedbyte[]at the specified position with the specified length.This
Signatureinstance is reset to the state of its last initialization for signing and thus can be used for another signature from the same identity.- Parameters:
outbuf- the buffer to store the signature.offset- the index of the first byte inoutbufto store.len- the number of bytes allocated for the signature.- Returns:
- the number of bytes stored in
outbuf. - Throws:
SignatureException- if thisSignatureinstance is not initialized properly.IllegalArgumentException- ifoffsetorlenare not valid in respect tooutbuf.
-
verify
Indicates whether the givensignaturecan be verified using the public key or a certificate of the signer.This
Signatureinstance is reset to the state of its last initialization for verifying and thus can be used to verify another signature of the same signer.- Parameters:
signature- the signature to verify.- Returns:
trueif the signature was verified,falseotherwise.- Throws:
SignatureException- if thisSignatureinstance is not initialized properly.
-
verify
Indicates whether the givensignaturestarting at indexoffsetwithlengthbytes can be verified using the public key or a certificate of the signer.This
Signatureinstance is reset to the state of its last initialization for verifying and thus can be used to verify another signature of the same signer.- Parameters:
signature- thebyte[]containing the signature to verify.offset- the start index insignatureof the signature.length- the number of bytes allocated for the signature.- Returns:
trueif the signature was verified,falseotherwise.- Throws:
SignatureException- if thisSignatureinstance is not initialized properly.IllegalArgumentException- ifoffsetorlengthare not valid in respect tosignature.
-
update
Updates the data to be verified or to be signed, using the specifiedbyte.- Parameters:
b- the byte to update with.- Throws:
SignatureException- if thisSignatureinstance is not initialized properly.
-
update
Updates the data to be verified or to be signed, using the specifiedbyte[].- Parameters:
data- the byte array to update with.- Throws:
SignatureException- if thisSignatureinstance is not initialized properly.
-
update
Updates the data to be verified or to be signed, using the givenbyte[], starting form the specified index for the specified length.- Parameters:
data- the byte array to update with.off- the start index indataof the data.len- the number of bytes to use.- Throws:
SignatureException- if thisSignatureinstance is not initialized properly.
-
update
Updates the data to be verified or to be signed, using the specifiedByteBuffer.- Parameters:
data- theByteBufferto update with.- Throws:
SignatureException- if thisSignatureinstance is not initialized properly.
-
toString
Returns a string containing a concise, human-readable description of thisSignatureincluding its algorithm and its state. -
setParameter
@Deprecated public final void setParameter(String param, Object value) throws InvalidParameterExceptionDeprecated.UsesetParameter(AlgorithmParameterSpec)instead.Sets the specified parameter to the given value.- Parameters:
param- the name of the parameter.value- the parameter value.- Throws:
InvalidParameterException- if the parameter is invalid, already set or is not allowed to be changed.
-
setParameter
public final void setParameter(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterExceptionSets the specifiedAlgorithmParameterSpec.- Parameters:
params- the parameter to set.- Throws:
InvalidAlgorithmParameterException- if the parameter is invalid, already set or is not allowed to be changed.
-
getParameters
Returns theAlgorithmParametersof thisSignatureinstance.- Returns:
- the
AlgorithmParametersof thisSignatureinstance, maybenull.
-
getParameter
Deprecated.There is no generally accepted parameter naming convention.Returns the value of the parameter with the specified name.- Parameters:
param- the name of the requested parameter value- Returns:
- the value of the parameter with the specified name, maybe
null. - Throws:
InvalidParameterException- ifparamis not a valid parameter for thisSignatureor an other error occurs.
-
clone
Description copied from class:ObjectCreates and returns a copy of thisObject. The default implementation returns a so-called "shallow" copy: It creates a new instance of the same class and then copies the field values (including object references) from this instance to the new instance. A "deep" copy, in contrast, would also recursively clone nested objects. A subclass that needs to implement this kind of cloning should callsuper.clone()to create the new instance and then create deep copies of the nested, mutable objects.- Overrides:
clonein classSignatureSpi- Returns:
- a copy of this object.
- Throws:
CloneNotSupportedException- if this object's class does not implement theCloneableinterface.
-