Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Signature

public abstract class Signature
extends SignatureSpi

java.lang.Object
   ↳ java.security.SignatureSpi
     ↳ java.security.Signature


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:

Summary

Constants

int SIGN

Constant that indicates that this Signature instance has been initialized for signing.

int UNINITIALIZED

Constant that indicates that this Signature instance has not yet been initialized.

int VERIFY

Constant that indicates that this Signature instance has been initialized for verification.

Fields

protected int state

Represents the current state of this Signature.

Inherited fields

From class java.security.SignatureSpi

Protected constructors

Signature(String algorithm)

Constructs a new instance of Signature with the name of the algorithm to use.

Public methods

final String getAlgorithm()

Returns the name of the algorithm of this Signature.

static Signature getInstance(String algorithm, String provider)

Returns a new instance of Signature that utilizes the specified algorithm from the specified provider.

static Signature getInstance(String algorithm, Provider provider)

Returns a new instance of Signature that utilizes the specified algorithm from the specified provider.

static Signature getInstance(String algorithm)

Returns a new instance of Signature that utilizes the specified algorithm.

final Object getParameter(String param)

This method was deprecated in API level 1. There is no generally accepted parameter naming convention.

final AlgorithmParameters getParameters()

Returns the AlgorithmParameters of this Signature instance.

final Provider getProvider()

Returns the provider associated with this Signature.

final void initSign(PrivateKey privateKey)

Initializes this Signature instance for signing, using the private key of the identity whose signature is going to be generated.

final void initSign(PrivateKey privateKey, SecureRandom random)

Initializes this Signature instance for signing, using the private key of the identity whose signature is going to be generated and the specified source of randomness.

final void initVerify(Certificate certificate)

Initializes this Signature instance for signature verification, using the certificate of the identity whose signature is going to be verified.

final void initVerify(PublicKey publicKey)

Initializes this Signature instance for signature verification, using the public key of the identity whose signature is going to be verified.

final void setParameter(String param, Object value)

This method was deprecated in API level 1. Use setParameter(AlgorithmParameterSpec) instead.

final void setParameter(AlgorithmParameterSpec params)

Sets the specified AlgorithmParameterSpec.

final byte[] sign()

Generates and returns the signature of all updated data.

final int sign(byte[] outbuf, int offset, int len)

Generates and stores the signature of all updated data in the provided byte[] at the specified position with the specified length.

String toString()

Returns a string containing a concise, human-readable description of this Signature including its algorithm and its state.

final void update(ByteBuffer data)

Updates the data to be verified or to be signed, using the specified ByteBuffer.

final void update(byte[] data, int off, int len)

Updates the data to be verified or to be signed, using the given byte[], starting form the specified index for the specified length.

final void update(byte b)

Updates the data to be verified or to be signed, using the specified byte.

final void update(byte[] data)

Updates the data to be verified or to be signed, using the specified byte[].

final boolean verify(byte[] signature)

Indicates whether the given signature can be verified using the public key or a certificate of the signer.

final boolean verify(byte[] signature, int offset, int length)

Indicates whether the given signature starting at index offset with length bytes can be verified using the public key or a certificate of the signer.

Inherited methods

From class java.security.SignatureSpi
From class java.lang.Object

Constants

SIGN

Added in API level 1
int SIGN

Constant that indicates that this Signature instance has been initialized for signing.

Constant Value: 2 (0x00000002)

UNINITIALIZED

Added in API level 1
int UNINITIALIZED

Constant that indicates that this Signature instance has not yet been initialized.

Constant Value: 0 (0x00000000)

VERIFY

Added in API level 1
int VERIFY

Constant that indicates that this Signature instance has been initialized for verification.

Constant Value: 3 (0x00000003)

Fields

state

Added in API level 1
int state

Represents the current state of this Signature. The three possible states are UNINITIALIZED, SIGN or VERIFY.

Protected constructors

Signature

Added in API level 1
Signature (String algorithm)

Constructs a new instance of Signature with the name of the algorithm to use.

Parameters
algorithm String: the name of algorithm to use.

Public methods

getAlgorithm

Added in API level 1
String getAlgorithm ()

Returns the name of the algorithm of this Signature.

Returns
String the name of the algorithm of this Signature.

getInstance

Added in API level 1
Signature getInstance (String algorithm, 
                String provider)

Returns a new instance of Signature that utilizes the specified algorithm from the specified provider.

Parameters
algorithm String: the name of the algorithm to use.
provider String: the name of the provider.
Returns
Signature a new instance of Signature that 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 if algorithm is null.
IllegalArgumentException if provider == null || provider.isEmpty()

getInstance

Added in API level 1
Signature getInstance (String algorithm, 
                Provider provider)

Returns a new instance of Signature that utilizes the specified algorithm from the specified provider. The provider supplied does not have to be registered.

Parameters
algorithm String: the name of the algorithm to use.
provider Provider: the security provider.
Returns
Signature a new instance of Signature that utilizes the specified algorithm from the specified provider.
Throws
NoSuchAlgorithmException if the specified algorithm is not available.
NullPointerException if algorithm is null.
IllegalArgumentException if provider == null

getInstance

Added in API level 1
Signature getInstance (String algorithm)

Returns a new instance of Signature that utilizes the specified algorithm.

Parameters
algorithm String: the name of the algorithm to use.
Returns
Signature a new instance of Signature that utilizes the specified algorithm.
Throws
NoSuchAlgorithmException if the specified algorithm is not available.
NullPointerException if algorithm is null.

getParameter

Added in API level 1
Object getParameter (String param)

This method was deprecated in API level 1.
There is no generally accepted parameter naming convention.

Returns the value of the parameter with the specified name.

Parameters
param String: the name of the requested parameter value
Returns
Object the value of the parameter with the specified name, maybe null.
Throws
InvalidParameterException if param is not a valid parameter for this Signature or an other error occurs.

getParameters

Added in API level 1
AlgorithmParameters getParameters ()

Returns the AlgorithmParameters of this Signature instance.

Returns
AlgorithmParameters the AlgorithmParameters of this Signature instance, maybe null.

getProvider

Added in API level 1
Provider getProvider ()

Returns the provider associated with this Signature.

Returns
Provider the provider associated with this Signature.

initSign

Added in API level 1
void initSign (PrivateKey privateKey)

Initializes this Signature instance for signing, using the private key of the identity whose signature is going to be generated.

Parameters
privateKey PrivateKey: the private key.
Throws
InvalidKeyException if privateKey is not valid.

initSign

Added in API level 1
void initSign (PrivateKey privateKey, 
                SecureRandom random)

Initializes this Signature instance for signing, using the private key of the identity whose signature is going to be generated and the specified source of randomness.

Parameters
privateKey PrivateKey: the private key.
random SecureRandom: the SecureRandom to use.
Throws
InvalidKeyException if privateKey is not valid.

initVerify

Added in API level 1
void initVerify (Certificate certificate)

Initializes this Signature instance for signature verification, using the certificate of the identity whose signature is going to be verified.

If the given certificate is an instance of X509Certificate and has a key usage parameter that indicates, that this certificate is not to be used for signing, an InvalidKeyException is thrown.

Parameters
certificate 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.

initVerify

Added in API level 1
void initVerify (PublicKey publicKey)

Initializes this Signature instance for signature verification, using the public key of the identity whose signature is going to be verified.

Parameters
publicKey PublicKey: the public key.
Throws
InvalidKeyException if publicKey is not valid.

setParameter

Added in API level 1
void setParameter (String param, 
                Object value)

This method was deprecated in API level 1.
Use setParameter(AlgorithmParameterSpec) instead.

Sets the specified parameter to the given value.

Parameters
param String: the name of the parameter.
value Object: the parameter value.
Throws
InvalidParameterException if the parameter is invalid, already set or is not allowed to be changed.

setParameter

Added in API level 1
void setParameter (AlgorithmParameterSpec params)

Sets the specified AlgorithmParameterSpec.

Parameters
params AlgorithmParameterSpec: the parameter to set.
Throws
InvalidAlgorithmParameterException if the parameter is invalid, already set or is not allowed to be changed.

sign

Added in API level 1
byte[] sign ()

Generates and returns the signature of all updated data.

This Signature instance is reset to the state of its last initialization for signing and thus can be used for another signature from the same identity.

Returns
byte[] the signature of all updated data.
Throws
SignatureException if this Signature instance is not initialized properly.

sign

Added in API level 1
int sign (byte[] outbuf, 
                int offset, 
                int len)

Generates and stores the signature of all updated data in the provided byte[] at the specified position with the specified length.

This Signature instance 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 byte: the buffer to store the signature.
offset int: the index of the first byte in outbuf to store.
len int: the number of bytes allocated for the signature.
Returns
int the number of bytes stored in outbuf.
Throws
SignatureException if this Signature instance is not initialized properly.
IllegalArgumentException if offset or len are not valid in respect to outbuf.

toString

Added in API level 1
String toString ()

Returns a string containing a concise, human-readable description of this Signature including its algorithm and its state.

Returns
String a printable representation for this Signature.

update

Added in API level 1
void update (ByteBuffer data)

Updates the data to be verified or to be signed, using the specified ByteBuffer.

Parameters
data ByteBuffer: the ByteBuffer to update with.
Throws
SignatureException if this Signature instance is not initialized properly.

update

Added in API level 1
void update (byte[] data, 
                int off, 
                int len)

Updates the data to be verified or to be signed, using the given byte[], starting form the specified index for the specified length.

Parameters
data byte: the byte array to update with.
off int: the start index in data of the data.
len int: the number of bytes to use.
Throws
SignatureException if this Signature instance is not initialized properly.

update

Added in API level 1
void update (byte b)

Updates the data to be verified or to be signed, using the specified byte.

Parameters
b byte: the byte to update with.
Throws
SignatureException if this Signature instance is not initialized properly.

update

Added in API level 1
void update (byte[] data)

Updates the data to be verified or to be signed, using the specified byte[].

Parameters
data byte: the byte array to update with.
Throws
SignatureException if this Signature instance is not initialized properly.

verify

Added in API level 1
boolean verify (byte[] signature)

Indicates whether the given signature can be verified using the public key or a certificate of the signer.

This Signature instance 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 byte: the signature to verify.
Returns
boolean true if the signature was verified, false otherwise.
Throws
SignatureException if this Signature instance is not initialized properly.

verify

Added in API level 1
boolean verify (byte[] signature, 
                int offset, 
                int length)

Indicates whether the given signature starting at index offset with length bytes can be verified using the public key or a certificate of the signer.

This Signature instance 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 byte: the byte[] containing the signature to verify.
offset int: the start index in signature of the signature.
length int: the number of bytes allocated for the signature.
Returns
boolean true if the signature was verified, false otherwise.
Throws
SignatureException if this Signature instance is not initialized properly.
IllegalArgumentException if offset or length are not valid in respect to signature.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.