public class RsaPssSignature extends PKCS11BufferingSignature
MGF1 is used as mask generation function, by default with SHA-1 as hash function (which by
default is also expected for data hash calculation). An alternative hash function
can be provided by calling method Signature.setParameter()
where the parameters have
to be supplied as iaik.pkcs.pkcs11.provider.signatures.PKCS11SignatureParameterSpec
(or maybe java.security.spec.PSSParameterSpec
or iaik.pkcs.pkcs1.RSAPssParameterSpec
)
on the signing side, or java.security.spec.PSSParameterSpec
or
iaik.pkcs.pkcs1.RSAPssParameterSpec
on the verification side where a software
delegate is used.
On the signing side Signature.setParameter()
must be called before initializing the
Signature engine (calling Signature.initSign()
; a typical workflow may look like
(for using SHA-256 as hash function):
// calculate the hash value over the data byte[] data = ...; MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(data); byte[] digest = md.digest(); // the PKCS#11 provider instance IAIKPkcs11 pkcs11Provider = new IAIKPkcs11(); // the private (PKCS#11) signing key PrivateKey privatekey = ...; // create Signature engine Signature signature = Signature.getInstance("RawRSAPSS", pcks11Provider); // create and set PSS parameters for SHA-256 Mechanism hashAlgorithm = Mechanism.get(PKCS11Constants.CKM_SHA256); long messageGenerationFunctionType = RSAPkcsParameters.MessageGenerationFunctionType.SHA256; int saltLength == 32; RSAPkcsPssParameters parameters = new RSAPkcsPssParameters(hashAlgorithm, messageGenerationFunctionType, saltLength); PKCS11SignatureParameterSpec paramSpec = new PKCS11SignatureParameterSpec(parameters); signature.setParameter(paramSpec); // init Signature engine for signing signatureEngine.initSign(signatureKey); // supply the digest calculated over the data signature.update(digest); // finish signature calculation byte[] signatureValue = signature.sign();On the verification side typically a software provider (like IAIK) will be used for verifying the signature, e.g.:
// calculate the hash value from the data byte[] data = ...; MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(data); byte[] digest = md.digest(); // the public (software) verification key PublicKey publickey = ...; // create and init Signature engine Signature signature = Signature.getInstance("RawRSAPSS","IAIK"); signature.initVerify(publicKey); // create and set PSS parameters for SHA-256 AlgorithmID hashID = (AlgorithmID)AlgorithmID.sha256.clone(); AlgorithmID mgfID = (AlgorithmID)AlgorithmID.mgf1.clone(); mgfID.setParameter(hashID.toASN1Object()); int saltLength = 32; RSAPssParameterSpec pssParamSpec = new RSAPssParameterSpec(hashID, mgfID, saltLength); signature.setParameter(pssParamSpec); // supply the digest calculated over the data signature.update(digest); // verify signature value boolean valid = signature.verify(signatureValue);
Modifier and Type | Field and Description |
---|---|
protected iaik.pkcs.pkcs11.Mechanism |
mechanism_
The mechanism of this siganture object which contains parameters also.
|
protected PKCS11SignatureParameterSpec |
parametersSpec_
The parameters for this signature object.
|
protected static java.lang.String |
SIGNATURE_ALGORITHM_NAME
The JCA standard name of this signature algorithm.
|
buffer_
currentKeyIsSoftwareKey_, initialized_, operationState_, pkcs11OperationInitialized_, privateKey_, publicKey_, session_, SIGN, softwareDelegate_, tokenManager_, usedMechanismInfos_, usedMechanisms_, VERIFY
Constructor and Description |
---|
RsaPssSignature()
Public default constructor to enable instantiation via Class.forName(String).
|
Modifier and Type | Method and Description |
---|---|
protected void |
engineSetParameter(java.security.spec.AlgorithmParameterSpec parametersSpec)
SPI: Set the parameters for this signature object.
|
protected java.lang.String |
getAlgorithmName()
Get the JCA standard name of this signautre algorithm.
|
protected iaik.pkcs.pkcs11.Mechanism |
getMechanism()
Get the mechanism of this signature object.
|
protected void |
pkcs11SetParameter(java.security.spec.AlgorithmParameterSpec parametersSpec)
SPI: Set the parameters for this signature object.
|
pkcs11InitSign, pkcs11InitVerify, pkcs11Sign, pkcs11Update, pkcs11Verify
engineGetParameter, engineInitSign, engineInitVerify, engineSetParameter, engineSign, engineUpdate, engineUpdate, engineVerify, finalize, finalizePkcs11Operation, getUsedMechanismFeatures, getUsedMechanisms, initializePkcs11Operation, initializeSession, initializeSoftwareDelegate, isSupportedBy, pkcs11GetParameter, pkcs11SetParameter, pkcs11Update
protected static java.lang.String SIGNATURE_ALGORITHM_NAME
protected PKCS11SignatureParameterSpec parametersSpec_
protected iaik.pkcs.pkcs11.Mechanism mechanism_
public RsaPssSignature()
Signature.getInstance("RawRSAPSS", pkcs11Provider);
.protected java.lang.String getAlgorithmName()
getAlgorithmName
in class PKCS11Signature
protected void engineSetParameter(java.security.spec.AlgorithmParameterSpec parametersSpec) throws java.security.InvalidAlgorithmParameterException
iaik.pkcs.pkcs11.provider.signatures.PKCS11SignatureParameterSpec
(or maybe a java.security.spec.PSSParameterSpec
or an
iaik.pkcs.pkcs1.RSAPssParameterSpec
) on the signing side or a
java.security.spec.PSSParameterSpec
or an iaik.pkcs.pkcs1.RSAPssParameterSpec
on the verification side where software delegate is used.engineSetParameter
in class PKCS11Signature
parametersSpec
- The AlgorithmParameterSpec containing the PSS parameters.java.security.InvalidAlgorithmParameterException
- if the given parameters are not supported.protected void pkcs11SetParameter(java.security.spec.AlgorithmParameterSpec parametersSpec) throws java.security.InvalidAlgorithmParameterException
iaik.pkcs.pkcs11.provider.signatures.PKCS11SignatureParameterSpec
(or maybe a java.security.spec.PSSParameterSpec
or an
iaik.pkcs.pkcs1.RSAPssParameterSpec
) on the signing side or a
java.security.spec.PSSParameterSpec
or an iaik.pkcs.pkcs1.RSAPssParameterSpec
on the verification side where software delegate is used.pkcs11SetParameter
in class PKCS11Signature
parametersSpec
- The AlgorithmParameterSpec containing the PSS parameters.java.security.InvalidAlgorithmParameterException
- if the given parameters are not supported.protected iaik.pkcs.pkcs11.Mechanism getMechanism()
getMechanism
in class PKCS11BufferingSignature
IAIK JavaSecurity Website https://jce.iaik.tugraz.at/
IAIK at Graz University of Technology, Austria, Europe
Copyright 2001-2023 IAIK, Graz University of Technology, Inffeldgasse 16a, 8010 Graz, Austria. All Rights Reserved. Version 1.9.4