public class SignatureAlgorithmImplHMAC extends SignatureAlgorithm
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
DEFAULT_ALGORITHM_URI_
The default algorithm URI for this algorithm implementation.
|
protected java.lang.String |
HMAC_JCA_ALGID_
The identifier used for the HMAC with SHA-1 algorithm within the Java Cryptography Architecture.
|
protected int |
maxLength_
The maximum length for the signature output.
|
protected int |
outputLength_
The length for the signature output.
|
protected java.security.Key |
secretKey_
The secret key used to compute the MAC.
|
input_, jCEProviderName_, privateKey_| Constructor and Description |
|---|
SignatureAlgorithmImplHMAC()
Standard constructor.
|
SignatureAlgorithmImplHMAC(java.lang.String URI,
java.lang.String HmacAlg)
Constructor that allows specific HMAC algorithms to be defined.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getOutputLength()
Gets the length of the signature output.
|
void |
setOutputLength(int outputLength)
Sets the length of the signature output.
|
void |
setParameters(org.w3c.dom.Element algorithmElement)
This algorithm takes the output length in bits as an optional parameter.
|
void |
setSignerKey(java.security.Key signerKey)
Sets the private key, which is used to compute the signature for the algorithm's input.
|
void |
setSignerKey(java.security.PrivateKey signerKey)
Sets the private key to be used by the signature algorithm.
|
void |
setVerifierKey(java.security.Key verifierKey)
Sets the public key, which is used to verify the signature for the algorithm's input.
|
java.io.InputStream |
sign()
Computes the signature value for the input previously provided by means of method
SignatureAlgorithm.setInput(java.io.InputStream). |
org.w3c.dom.Element |
toElement(org.w3c.dom.Document signatureDOMDoc)
Returns the DOM element representation of the algorithm.
|
boolean |
verifierKeyUnknown()
Gets the information, if this signature algorithm knows about the verification key.
|
boolean |
verify(java.io.InputStream signature)
Verifies the specified signature for the input data previously set with method
SignatureAlgorithm.setInput(java.io.InputStream). |
setInput, setJCEProviderNameprotected java.lang.String DEFAULT_ALGORITHM_URI_
protected java.lang.String HMAC_JCA_ALGID_
protected java.security.Key secretKey_
protected int outputLength_
protected int maxLength_
public SignatureAlgorithmImplHMAC()
http://www.w3.org/2000/09/xmldsig#hmac-sha1. Sets the default output length to 160 bits.public SignatureAlgorithmImplHMAC(java.lang.String URI,
java.lang.String HmacAlg)
For example, the default constructor uses HMAC-SHA1
URI: http://www.w3.org/2000/09/xmldsig#hmac-sha1 JCE AlgID: HMAC/SHANote: This constructor does not take any parameters, so only HMAC based algorithms that do not require parameters may be used
URI - The URI to use for the specified signature algorithmHmacAlg - The HMAC JCA/JCE algorithm String which identifies the algorithm to usepublic void setParameters(org.w3c.dom.Element algorithmElement)
throws AlgorithmException
setParameters in class AlgorithmalgorithmElement - The DOM element representation of the algorithm, as it will be found by IXSIL
in the XML signature. Must not be null.AlgorithmException - if an invalid output length parameter has been specified, or if reading
the parameter Element fails for any other reason.public void setOutputLength(int outputLength)
throws AlgorithmException
outputLength - The signature output length in bits. Must be a multiple of 8 and must meet the
boundaries [8, 160].AlgorithmException - if outputLength does not meet the conditions specified above.public int getOutputLength()
public org.w3c.dom.Element toElement(org.w3c.dom.Document signatureDOMDoc)
throws AlgorithmException
toElement in class AlgorithmsignatureDOMDoc - The DOM document which should be used to create necessary DOM nodes. Must not
be null.AlgorithmException - if no identifying URI has been specified for this algorithm.public java.io.InputStream sign()
throws AlgorithmException
SignatureAlgorithm.setInput(java.io.InputStream).
The length of the output depends on the selected output length. If no output length has been set
explicitely with method setOutputLength(int), the default output length will be 160 bits.sign in class SignatureAlgorithmSignatureAlgorithm.setInput(java.io.InputStream). This value will NOT
be base64 encoded.AlgorithmException - if the signer key or the input data have not been set, or if computing
the signature value fails for any reason.public boolean verify(java.io.InputStream signature)
throws AlgorithmException
SignatureAlgorithm.setInput(java.io.InputStream).verify in class SignatureAlgorithmsignature - The bytes representing the signature to be verified. Must not be null.true, if the signature is valid, false otherwise.AlgorithmException - if the verifier key or the input data have not been set, or if verifying
the signature fails for any reason.public void setSignerKey(java.security.Key signerKey)
signerKey - The private key for computing the signature. Must not be null.public void setVerifierKey(java.security.Key verifierKey)
setVerifierKey in class SignatureAlgorithmverifierKey - The public key for verifying the signature. Must not be null.public boolean verifierKeyUnknown()
setVerifierKey(java.security.Key) or not.verifierKeyUnknown in class SignatureAlgorithmtrue, if this signature algorithm does not know about the verification key.public void setSignerKey(java.security.PrivateKey signerKey)
throws AlgorithmException
setSignerKey in class SignatureAlgorithmprivatekey - The private key to be used by the signature algorithm.AlgorithmException