public class IaikPkcs11CmsSecurityProvider
extends iaik.cms.ecc.IaikEccProvider
SecurityProvider
for the IAIK-CMS toolkit. This
SecurityProvider
can handle IAIKPKCS11Key
objects and is thus suitable
for use with the PKCS#11 provider. The demos in this package use this class to get the IAIK-CMS
library to use a PKCS#11 module instead of pure software crypto.
To install this security provider call:
SecurityProvider
Modifier and Type | Field and Description |
---|---|
protected IAIKPkcs11 |
iaikPkcs11Provider_
Reference to the installed PKCS#11 provider instance.
|
ecka_eg_X963KDF_SHA256, ecka_eg_X963KDF_SHA384, ecka_eg_X963KDF_SHA512
ALG_SIGNATURE_RAWRSA, ALG_SIGNATURE_RAWRSASSA_PKCS1_V15
ALG_CIPHER_RSA, ALG_CIPHER_RSA_DECRYPT, ALG_CIPHER_RSA_ENCRYPT, ALG_CIPHER_RSA_SIGN, ALG_CIPHER_RSA_VERIFY, ALG_DIGEST_MD5, ALG_DIGEST_SHA, ALG_HMAC_MD5, ALG_HMAC_SHA, ALG_KEYEX_DH, ALG_KEYEX_ESDH, ALG_KEYEX_SSDH, ALG_SIGNATURE_RAWDSA, ALG_SIGNATURE_RAWECDSA, ALG_SIGNATURE_RAWECDSA_PLAIN, ALG_SIGNATURE_RAWRSAPSS, ALG_SIGNATURE_SHADSA, CIPHER_DECRYPT, CIPHER_ENCRYPT, CIPHER_NONE, CIPHER_UNWRAP, CIPHER_WRAP, COMPRESS, DECOMPRESS, IMPLEMENTATION_NAME_DSA, IMPLEMENTATION_NAME_ECDSA, IMPLEMENTATION_NAME_ECDSA_PLAIN, IMPLEMENTATION_NAME_PBKDF2, IMPLEMENTATION_NAME_PWRI_KEK, IMPLEMENTATION_NAME_RSA, IMPLEMENTATION_NAME_RSA_OAEP, IMPLEMENTATION_NAME_RSA_PSS, providerName_, random_, SIGNATURE_NONE, SIGNATURE_SIGN, SIGNATURE_VERIFY
Constructor and Description |
---|
IaikPkcs11CmsSecurityProvider(IAIKPkcs11 iaikPkcs11Provider)
The given PKCS#11 provider instance must already be installed in the JCA framework.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
calculateSignatureFromHash(iaik.asn1.structures.AlgorithmID signatureAlgorithm,
iaik.asn1.structures.AlgorithmID digestAlgorithm,
java.security.PrivateKey privateKey,
byte[] digest)
Calculates the signature value for a CMS SignerInfo over the given digest value with the given
algorithm using the supplied private key.
|
byte[] |
calculateSignatureFromSignedAttributes(iaik.asn1.structures.AlgorithmID signatureAlgorithm,
iaik.asn1.structures.AlgorithmID digestAlgorithm,
java.security.PrivateKey privateKey,
byte[] signedAttributes)
Calculates the signature value for a CMS SignerInfo over the given signed attributes with the
given algorithm using the supplied private key.
|
javax.crypto.SecretKey |
decryptKey(byte[] encryptedKey,
iaik.asn1.structures.AlgorithmID kea,
java.security.PrivateKey recipientKey,
java.lang.String cekAlgorithmName)
Decrypts the given encrypted content encryption key for a
KeyTransRecipientInfo . |
java.security.Signature |
getSignature(java.lang.String algorithm,
int mode,
java.security.Key key)
This method returns the desired Signature object which uses the PKCS#11 provider if the key is
a PKCS#11 key.
|
calculateSharedSecret, checkDomainParameters, createSharedKeyEncryptionKey, generateKeyAgreementKeyPair, getASN1OriginatorPublicKey, getKeyLength, getKeyLength, getOriginatorPublicKey
deriveKey, generateKey, getAlgorithmParameterSpec, getPBEKey, getSecureRandom, setIv, turnOffIAIKProviderVersionCheck, unwrapKey, verifySignatureFromHash, verifySignatureFromSignedAttributes, wrapKey
calculateMac, compress, convertCipherMode, decryptKey, encryptKey, generateKey, getAlgorithmParameters, getAlgorithmParameters, getAlgorithmParameters, getAuthCipherEngine, getAuthCipherEngine, getByteArrayAuthCipherEngine, getByteArrayAuthCipherEngine, getByteArrayCipherEngine, getByteArrayCipherEngine, getCipher, getCipher, getCipher, getCipher, getHash, getInputStreamAuthCipherEngine, getInputStreamAuthCipherEngine, getInputStreamCipherEngine, getInputStreamCipherEngine, getInputStreamCompressEngine, getInputStreamHashEngine, getInputStreamMacEngine, getKeyAgreement, getKeyFactory, getKeyGenerator, getKeyGenerator, getKeyLength, getKeyPairGenerator, getMac, getMac, getMessageDigest, getMessageDigest, getMicAlgs, getOutputStreamCompressEngine, getOutputStreamHashEngine, getOutputStreamMacEngine, getProviderName, getSecretKeyFactory, getSecurityProvider, getSignature, getSignature, getSignature, getSignatureParameters, setSecureRandom, setSecurityProvider, setSignatureParameters
protected IAIKPkcs11 iaikPkcs11Provider_
public IaikPkcs11CmsSecurityProvider(IAIKPkcs11 iaikPkcs11Provider)
iaikPkcs11Provider
- The PKCS#11 provider instance to use in this CMS security provider.public byte[] calculateSignatureFromHash(iaik.asn1.structures.AlgorithmID signatureAlgorithm, iaik.asn1.structures.AlgorithmID digestAlgorithm, java.security.PrivateKey privateKey, byte[] digest) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.SignatureException
Each SignerInfo
included in a CMS SignedData object may calculate
the signature value differently depending on the presence of signed attributes:
SignerInfo
for calculating the
signature when no signed attributes are present. Since the data to be signed may be of
arbitrary size this method expects the already hashed data to only calculate the signature
value on it (for instance, by doing the digest encrypting when using RSA for signing).
For that reason, when writing your own SecurityProvider and overriding this method, you will need some kind of RAW signature (respectively digest encryption) mechanism only expecting the already hashed data (e.g. a "RawDSA" signature engine when using DSA repectively a Cipher engine when using RSA).
If you want to override this method for use with smartcards, please be sure that your smartcard
is able to do the signature (respectively digest encryption) operation only. However, if your
smartcard requires to supply the whole data for doing the hash calcualtion itself, you may
ensure that your SignerInfo
contains signed attributes and override
method calculateSignatureFromSignedAttributes
for calculating the signature over the DER encoding of the signed attributes (thereby doing the
hash computation, too).
calculateSignatureFromHash
in class iaik.cms.IaikProvider
signatureAlgorithm
- signatureAlgorithm the signature algorithm to be used, e.g. rsaEncryption, DSAdigestAlgorithm
- the digest algorithm used for hash computation (e.g. SHA-1 or MD5); may be necessary
for some signature schemes (e.g. to be included as a DigestInfo in a PKCS#1 RSA
signature)privateKey
- the private key of the signer (i.e. the one supplied when creating a
SignerInfo
object; may be some kind of "dummy" key when
used for smartcardsdigest
- the digest value over which the signature shall be calculatedjava.security.NoSuchAlgorithmException
- if any of the required algorithms is not supportedjava.security.InvalidKeyException
- if the key is not validjava.security.SignatureException
- if signature verification fails because of some crypto related errorpublic byte[] calculateSignatureFromSignedAttributes(iaik.asn1.structures.AlgorithmID signatureAlgorithm, iaik.asn1.structures.AlgorithmID digestAlgorithm, java.security.PrivateKey privateKey, byte[] signedAttributes) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.SignatureException
Each SignerInfo
included in a CMS SignedData object may calculate
the signature value differently depending on the presence of signed attributes:
SignerInfo
for calculating the
signature when signed attributes are present.
When writing your own SecurityProvider and overriding this method, be aware that only the --
yet NOT hashed -- DER encoding of the signed attributes is supplied to this method. For that
reason this method can be overriden for use with smartcards requiring to do the digest
calculation theirselves: ensure that your SignerInfo
contains
signed attributes and override this method in a way to pass the given DER encoding of the
signed attributes to your smartcard for doing the signature (and digest) calculation.
Since this method requires to calculate the digest value over the DER encoded signed attributes as part of the signature calculation, it uses a ordinary JCA Signature engine.
calculateSignatureFromSignedAttributes
in class iaik.cms.IaikProvider
signatureAlgorithm
- signatureAlgorithm the signature algorithm to be used, e.g. rsaEncryption, DSAdigestAlgorithm
- the digest algorithm to be used for hash computation (e.g. SHA-1,..., SHA-512); may be
necessary for some signature schemes (e.g. to be included as a DigestInfo in a PKCS#1
RSA signature)privateKey
- the private key of the signer (i.e. the one supplied when creating a
SignerInfo
object; may be some kind of "dummy" key when
used for smartcardssignedAttributes
- the DER encoding of the signed attributes over which the signature shall be calculatedjava.security.NoSuchAlgorithmException
- if no Signature engine is available for the requested algorithmjava.security.InvalidKeyException
- if the key is not validif
- signature calculation failsjava.security.SignatureException
public java.security.Signature getSignature(java.lang.String algorithm, int mode, java.security.Key key) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmException
SIGNATURE_SIGN
or SIGNATURE_VERIFY
the
signature object has to be initialized with the provided key in the respective mode.getSignature
in class iaik.cms.SecurityProvider
algorithm
- the name of the Signature algorithmmode
- the mode indicating if the engine has to be initializedkey
- the key for initializing the Signature enginejava.security.InvalidKeyException
- if the key is not validjava.security.NoSuchAlgorithmException
- if no Signature engine is available for the requested algorithmpublic javax.crypto.SecretKey decryptKey(byte[] encryptedKey, iaik.asn1.structures.AlgorithmID kea, java.security.PrivateKey recipientKey, java.lang.String cekAlgorithmName) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, javax.crypto.NoSuchPaddingException, javax.crypto.BadPaddingException
KeyTransRecipientInfo
.
CMS EnvelopedData
uses the KeyTransRecipientInfo
type for encrypting the secret content encryption key with the public
key of the recipient. Currently in general RSA PKCS#1v1.5 is used for key transport. If
rsaEncryption is requested as key encryption algorithm this method uses a RSA Cipher
("RSA/ECB/PKCS1Padding/Encrypt") for decrypting the encrypted content encryption key with the
supplied private key of the recipient. If another algorithm than RSA is requested, this method
throws a NoSuchAlgorithmException. An application wishing to support another algorithm may
override this method.
decryptKey
in class iaik.cms.IaikProvider
encryptedKey
- the encrypted content encryption key to be decryptedkea
- the key encryption alglorithm to be used, e.g. rsaEncryptionrecipientKey
- the private key of the recipient to be used for decrypting the encrypted content
encryption keycekAlgorithmName
- the name of the content encryption key (e.g. "DES") to be set for the SecretKey object
created by this methodjava.security.NoSuchAlgorithmException
- if the requested algorithm is not availablejava.security.InvalidKeyException
- if the decryption key is not validjavax.crypto.NoSuchPaddingException
- if the required padding scheme is not supportedjavax.crypto.BadPaddingException
- if an padding error occursIAIK 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