|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object iaik.cms.SecurityProvider
public class SecurityProvider
This class centralizes all cryptographic operations used for CMS.
With this class IAIK-CMS adopts the SecurityProvider model introduced by the IAIK-SSL library iSaSiLk. The SecurityProvider model used here is similar to that of iSaSiLk except for a the following changes:
iaik.x509.X509certificate
,
and any attribute certificate has to be supplied as
iaik.x509.attr.AttributeCertificate
. An application wishing
to use certificates from other providers may use methods
convertCertificateChain
and convertToAttributeCertificateChain
of the IAIK-JCE crypto toolkit for converting them into the IAIK X.509 representation before using them
with IAIK-CMS. Please note that both, iaik.x509.X509Certificate
and
iaik.x509.attr.AttributeCertificate
fit into the JCA cert API
because being descendants of java.security.cert.Certificate
.
Unfortunately java.security.cert.Certificate
only groups
public key certificates; so iaik.x509.attr.AttributeCertificate
returns null
when calling method getPublicKey
.
getEngine
methods of this SecurityProvider does
not specify the requested engine by its name; rather the engines are
requested by its AlgorithmIDs as used with CMS
generateKeyAgreementKeyPair(AlgorithmID keyAgreeAlgorithm, PublicKey
otherKey)
has to throw an exception and has to be implemented if using
another cryptographic provider than IAIK. The same applies to method
#createSharedKeyEncryptionKey(AlgorithmID, PrivateKey, PublicKey, AlgorithmID, int,
byte[], String) createSharedKeyEncryptionKey} which cannot handle an ESDHKeyAgreement
in provider independent way. So at the current state it might be preferable to
override all ESDH related methods when intending to use another provider than IAIK.
With class IaikProvider
IAIK-CMS contains an
SecurityProvider implementation for the IAIK cryptography provider
of the crypto toolkit IAIK-JCE. Please note the difference: The IAIK
provider is a JCA/JCE cryptography provider supplying cryptographic engines;
Class IaikProvider is an IAIK-CMS SecurityProvider implementation that
makes the cryptographic engines of the IAIK JCA/JCE cyrptography provider
available for IAIK-CMS.
Per default IAIK-CMS is configured to look if the IAIK cryptography provider is available. If yes, it uses the IaikProvider as SecurityProvider. If not it uses an instance of this class. So if you want to use the IAIK provider you do not have to make any care about the SecurityProvider setting. However, if you do not want to use the IAIK provider for some reasons (e.g. you require a specific, e.g. smartcard depending, handling for some tasks) you have two options:
SecurityProvider.setSecurityProvider(new SecurityProvider());
MySecurityProvider mySecurityProvider = ...; SecurityProvider.setSecurityProvider(mySecurityProvider);
public class MySecurityProvider extends IaikProvider { public byte[] calculateSignatureFromSignedAttributes(AlgorithmID signatureAlgorithm, AlgorithmID digestAlgorithm, PrivateKey privateKey, byte[] signedAttributes) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException { // get the implementation name: RSA? (note that CMS indicates rsaEncryption as Signature algorithm) String implementationName = signatureAlgorithm.getImplementationName(); if (implementationName.equals(IMPLEMENTATION_NAME_RSA)) { // let the smartcard calculate the signature value byte[] signatureValue = ...; } else { return super.calculateSignatureFromSignedAttributes(signatureAlgorithm, digestAlgorithm, privateKey, signedAttributes); } } }In the second case, i.e. you want to use a different provider alltogether and not use the IAIK JCE at all (for whatever reason ;-) it will be easiest to start with the SecurityProvider class and override those methods where you cannot use the default implementation.
Note that you also may install a SecurityProvider per CMS object. To, for instance,
use one specific SecurityProvider only for one specific SignedDataStream
object, you may use its setSecurityProvider
method, e.g.:
MySecurityProvider myProvider = ...; SignedDataStream signedData = ...; signedData.setSecurityProvider(myProvider);Now myProvider will be used for any cryptographic operation required by this one specific SignedDataStream object. If any of the CMS objects (SignerInfos) belonging to this SignedDataStream object need a SecurityProvider, they will use myProvider, too; except for those, who already have installed their own SecurityProvider. However, SecurityProviders are only forwarded from "higher" to "lower" objects, e.g.: if a SignedData(Stream) object has its own SecurityProvider it forwards it to its SignerInfos objects (as long as they do not already have their own SecurityProviders), but if a SignerInfo with its own SecurityProvider is added to a SignedData(Stream) object that has no SecurityProvider installed, the SecurityProvider of the SignerInfo is not forwarded to the SignedData(Stream) object. In this case the SignedDataStream object will use the default, system-wide installed SecurityProvider (which should be available in any case).
setSecurityProvider
(if present), or if you already
may install it via the constructor (which may required when, for instance, parsing a CMS object
that needs cryptographic engines already during the parsing procedure (e.g. for digest calculation
initialization when parsing a SignedData object)).
IaikProvider
Field Summary | |
---|---|
static java.lang.String |
ALG_CIPHER_RSA
Constant string RSA/ECB/PKCS1Padding . |
static java.lang.String |
ALG_CIPHER_RSA_DECRYPT
Constant string RSA/ECB/PKCS1Padding/Decrypt . |
static java.lang.String |
ALG_CIPHER_RSA_ENCRYPT
Constant string RSA/ECB/PKCS1Padding/Encrypt . |
static java.lang.String |
ALG_CIPHER_RSA_SIGN
Constant string RSA/ECB/PKCS1Padding/Sign . |
static java.lang.String |
ALG_CIPHER_RSA_VERIFY
Constant string RSA/ECB/PKCS1Padding/Verify . |
static java.lang.String |
ALG_DIGEST_MD5
Constant string MD5 . |
static java.lang.String |
ALG_DIGEST_SHA
Constant string SHA . |
static java.lang.String |
ALG_HMAC_MD5
Constant string HmacMD5 . |
static java.lang.String |
ALG_HMAC_SHA
Constant string HmacSHA1 . |
static java.lang.String |
ALG_KEYEX_DH
Constant string DH |
static java.lang.String |
ALG_KEYEX_ESDH
Constant string ESDH |
static java.lang.String |
ALG_KEYEX_SSDH
Constant string SSDH |
static java.lang.String |
ALG_SIGNATURE_RAWDSA
Constant string RawDSA . |
static java.lang.String |
ALG_SIGNATURE_RAWECDSA
Constant string RawECDSA . |
static java.lang.String |
ALG_SIGNATURE_RAWECDSA_PLAIN
Constant string RawECDSAPlain . |
static java.lang.String |
ALG_SIGNATURE_RAWRSAPSS
Constant string RawRSAPSS . |
static java.lang.String |
ALG_SIGNATURE_SHADSA
Constant string SHA1withDSA . |
static int |
CIPHER_DECRYPT
Constant for a cipher object which is to be initialized for decryption. |
static int |
CIPHER_ENCRYPT
Constant for a cipher object which is to be initialized for encryption. |
static int |
CIPHER_NONE
Constant for a cipher object which is not to be initialized. |
static int |
CIPHER_UNWRAP
Constant for a cipher object which is to be initialized for decryption. |
static int |
CIPHER_WRAP
Constant for a cipher object which is to be initialized for key wrap. |
static int |
COMPRESS
Constant for a compress engine to be initialized for compression. |
static int |
DECOMPRESS
Constant for a compress engine to be initialized for decompression. |
static java.lang.String |
IMPLEMENTATION_NAME_DSA
Constant string SHA-1/DSA . |
static java.lang.String |
IMPLEMENTATION_NAME_ECDSA
Constant string ECDSA . |
static java.lang.String |
IMPLEMENTATION_NAME_ECDSA_PLAIN
Constant string ECDSAPlain . |
static java.lang.String |
IMPLEMENTATION_NAME_PBKDF2
Constant string PBKDF2 . |
static java.lang.String |
IMPLEMENTATION_NAME_PWRI_KEK
Constant string PWRI-KEK . |
static java.lang.String |
IMPLEMENTATION_NAME_RSA
Constant string RSA . |
static java.lang.String |
IMPLEMENTATION_NAME_RSA_OAEP
Constant string RSAES-OAEP . |
static java.lang.String |
IMPLEMENTATION_NAME_RSA_PSS
Constant string RSASSA-PSS . |
protected java.security.Provider |
provider_
The JCA/JCE Provider instance to be used. |
protected java.lang.String |
providerName_
The name of the underlying cryptographic provider, if installed. |
protected java.security.SecureRandom |
random_
The SecureRandom. |
static int |
SIGNATURE_NONE
Constant for a signature object which is not to be initialized. |
static int |
SIGNATURE_SIGN
Constant for a signature object which is to be initialized for signing. |
static int |
SIGNATURE_VERIFY
Constant for a signature object which is to be initialized for verification. |
Constructor Summary | |
---|---|
SecurityProvider()
Default constructor. |
|
SecurityProvider(java.security.Provider provider)
Creates a SecurityProvider for the given cryptographic provider to use. |
|
SecurityProvider(java.lang.String providerName)
Creates a SecurityProvider for the given cryptographic provider to use. |
Method Summary | |
---|---|
byte[] |
calculateMac(AlgorithmID algorithmID,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec paramSpec,
byte[] data)
Calculates a Message Authentication Code on the given data. |
byte[] |
calculateSharedSecret(AlgorithmID keyAgreementAlgorithm,
java.security.Key key,
java.security.Key otherKey,
java.security.spec.AlgorithmParameterSpec paramSpec)
This method uses the specified KeyAgreement algorithm to calculate a shared secret between the owners of the given private and public key. |
byte[] |
calculateSignatureFromHash(AlgorithmID signatureAlgorithm,
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(AlgorithmID signatureAlgorithm,
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. |
void |
checkDomainParameters(java.security.PrivateKey myKey,
java.security.PublicKey otherKey)
Checks if the given private and public key agreement keys have the same domain parameters. |
byte[] |
compress(AlgorithmID compressAlg,
byte[] data,
int compressionMode)
Uses the given compression algorithm to compress/decompress the supplied input data. |
static int |
convertCipherMode(int mode)
Converts the SecurityProvider Cipher mode to the javax.crypto Cipher mode. |
javax.crypto.SecretKey |
createSharedKeyEncryptionKey(AlgorithmID keyAgreeAlg,
java.security.PrivateKey myKey,
java.security.PublicKey otherKey,
AlgorithmID kea,
int kekLength,
byte[] ukm,
java.lang.String kekName)
Create a shared secret key encryption key for the given key agree algorithm. |
javax.crypto.SecretKey |
decryptKey(byte[] encryptedKey,
AlgorithmID kea,
java.security.PrivateKey recipientKey)
Decrypts the given encrypted content encryption key for a KeyTransRecipientInfo . |
javax.crypto.SecretKey |
decryptKey(byte[] encryptedKey,
AlgorithmID kea,
java.security.PrivateKey recipientKey,
java.lang.String cekAlgorithmName)
Decrypts the given encrypted content encryption key for a KeyTransRecipientInfo . |
java.security.Key |
deriveKey(char[] password,
AlgorithmID keyDerivationAlg,
java.security.spec.AlgorithmParameterSpec paramSpec)
Uses the requested key derivation function to create a secret key from the supplied password. |
byte[] |
encryptKey(javax.crypto.SecretKey cek,
AlgorithmID kea,
java.security.PublicKey recipientKey)
Encrypts the given secret content encryption key for a KeyTransRecipientInfo . |
java.security.spec.AlgorithmParameterSpec |
generateAEADParamSpec(AlgorithmID contentAuthEncAlg,
byte[] encodedAuthAttributes,
byte[] mac,
long inputLength)
Generates an AlgorithmParameterSpec for the given content-authenticated encryption algorithm. |
java.security.spec.AlgorithmParameterSpec |
generateAEADParamSpec(AlgorithmID contentAuthEncAlg,
byte[] encodedAuthAttributes,
long inputLength)
Generates an AlgorithmParameterSpec for the given content-authenticated encryption algorithm. |
java.security.spec.AlgorithmParameterSpec |
generateGCMParamSpec(AlgorithmID contentAuthEncAlg)
Generates a GCM AlgorithmParameterSpec ( javax.crypto.spec.GCMParameterSpec ; only
available since Java 7) for the given content-authenticated encryption algorithm. |
javax.crypto.SecretKey |
generateKey(AlgorithmID algorithm,
java.security.spec.AlgorithmParameterSpec paramSpec)
Generates a SecretKey for the requested algorithm. |
javax.crypto.SecretKey |
generateKey(AlgorithmID algorithm,
int keyLength)
Generates a SecretKey for the requested algorithm. |
java.security.KeyPair |
generateKeyAgreementKeyPair(AlgorithmID keyAgreeAlgorithm,
java.security.PublicKey otherKey)
Generates a key pair with same domain parameters of the given public key for the given key agreement method. |
java.security.AlgorithmParameters |
getAlgorithmParameters(AlgorithmID algorithm)
Gets the algorithm parameters from the given AlgorithmID. |
java.security.AlgorithmParameters |
getAlgorithmParameters(AlgorithmID algorithmID,
java.lang.String algorithm)
Gets the algorithm parameters with the given name from the given AlgorithmID. |
java.security.AlgorithmParameters |
getAlgorithmParameters(java.lang.String algorithm)
Gets an AlgorithmParameters instance for the requested algorithm. |
java.security.spec.AlgorithmParameterSpec |
getAlgorithmParameterSpec(AlgorithmID algID)
Gets algorithm parameter specification from the given AlgorithmID. |
ASN1Object |
getASN1OriginatorPublicKey(java.security.PublicKey originatorPublicKey)
Gets an ASN.1 representation of the provided originator public key. |
AuthCipherEngine |
getAuthCipherEngine(AlgorithmID algorithm,
int mode,
java.security.Key key,
java.security.AlgorithmParameters params,
byte[] aad)
Gets an AuthCipherEngine for authenticated data encryption. |
AuthCipherEngine |
getAuthCipherEngine(AlgorithmID algorithm,
int mode,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec params,
byte[] aad)
Gets an AuthCipherEngine for authenticated data encryption. |
ByteArrayAuthCipherEngine |
getByteArrayAuthCipherEngine(AlgorithmID algorithm,
int mode,
java.security.Key key,
java.security.AlgorithmParameters params,
byte[] aad)
Gets a ByteArrayAuthCipherEngine for authenticated en/decrypting data supplied by some byte array. |
ByteArrayAuthCipherEngine |
getByteArrayAuthCipherEngine(AlgorithmID algorithm,
int mode,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec params,
byte[] aad)
Gets a ByteArrayAuthCipherEngine for en/decrypting data supplied by some byte array. |
ByteArrayCipherEngine |
getByteArrayCipherEngine(AlgorithmID algorithm,
int mode,
java.security.Key key,
java.security.AlgorithmParameters params)
Gets a ByteArrayCipherEngine for en/decrypting data supplied by some byte array. |
ByteArrayCipherEngine |
getByteArrayCipherEngine(AlgorithmID algorithm,
int mode,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec params)
Gets a ByteArrayCipherEngine for en/decrypting data supplied by some byte array. |
javax.crypto.Cipher |
getCipher(AlgorithmID algorithm,
int mode,
java.security.Key key,
java.security.AlgorithmParameters params)
Returns the desired Cipher object for the requested algorithm. |
javax.crypto.Cipher |
getCipher(AlgorithmID algorithm,
int mode,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec params)
Returns the desired Cipher object for the requested algorithm. |
javax.crypto.Cipher |
getCipher(java.lang.String algorithm,
int mode,
java.security.Key key,
java.security.AlgorithmParameters params)
This method returns the desired Cipher object. |
javax.crypto.Cipher |
getCipher(java.lang.String algorithm,
int mode,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec params)
This method returns the desired Cipher object. |
java.security.spec.AlgorithmParameterSpec |
getEllipticCurveParameterSpec(java.lang.String curveName)
Creates an EC AlgorithmParameterSpec for the given curve name. |
byte[] |
getHash(AlgorithmID algorithm,
byte[] data)
Calculates the hash on the given data using the requested hash algorithm. |
InputStreamAuthCipherEngine |
getInputStreamAuthCipherEngine(AlgorithmID algorithm,
int mode,
java.security.Key key,
java.security.AlgorithmParameters params,
byte[] aad)
Gets an InputStreamAuthCipherEngine for authenticated en/decrypting data read from some input stream. |
InputStreamAuthCipherEngine |
getInputStreamAuthCipherEngine(AlgorithmID algorithm,
int mode,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec params,
byte[] aad)
Gets an InputStreamAuthCipherEngine for authenticated en/decrypting data read from some input stream. |
InputStreamCipherEngine |
getInputStreamCipherEngine(AlgorithmID algorithm,
int mode,
java.security.Key key,
java.security.AlgorithmParameters params)
Gets an InputStreamCipherEngine for en/decrypting data read from some input stream. |
InputStreamCipherEngine |
getInputStreamCipherEngine(AlgorithmID algorithm,
int mode,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec params)
Gets an InputStreamCipherEngine for en/decrypting data read from some input stream. |
InputStreamCompressEngine |
getInputStreamCompressEngine(AlgorithmID compressAlg,
java.io.InputStream is,
int compressionMode,
int bufferSize)
Gets an InputStreamCompressEngine for compressing/decompressing data read from some input stream. |
InputStreamHashEngine |
getInputStreamHashEngine(AlgorithmID algorithm,
java.io.InputStream is)
Returns an InputStreamHashEngine for calculating the hash value on the data supplied from the given input stream. |
InputStreamMacEngine |
getInputStreamMacEngine(AlgorithmID algorithm,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec paramSpec,
java.io.InputStream is)
Gets an InputStreamMacEngine for calculating a Message Authentication Code on data read from some input stream. |
javax.crypto.KeyAgreement |
getKeyAgreement(AlgorithmID keyAgreementAlgorithm,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec paramSpec)
This method returns the desired KeyAgreement object. |
AlgorithmID |
getKeyAlgorithmID(java.security.PrivateKey privateKey)
Gets the AlgorithmID of the given private key. |
java.security.KeyFactory |
getKeyFactory(AlgorithmID algorithm)
This method returns the desired KeyFactory object. |
javax.crypto.KeyGenerator |
getKeyGenerator(AlgorithmID algorithm,
java.security.spec.AlgorithmParameterSpec paramSpec)
Returns a KeyGenerator for the requested algorithm. |
javax.crypto.KeyGenerator |
getKeyGenerator(AlgorithmID algorithm,
int keyLength)
Return a KeyGenerator for the requested algorithm. |
javax.crypto.KeyGenerator |
getKeyGenerator(java.lang.String algorithm,
int keyLength)
Returns a KeyGenerator for the requested algorithm. |
int |
getKeyLength(java.security.Key key)
Calculates the length of the given key. |
int |
getKeyLength(java.security.PrivateKey privKey)
Calculates the length of the given private key. |
int |
getKeyLength(java.security.PublicKey pubKey)
Calculates the length of the given public key. |
java.security.KeyPairGenerator |
getKeyPairGenerator(AlgorithmID algorithm)
Return a KeyPairGenerator for the requested algorithm. |
java.security.KeyStore |
getKeyStore(java.lang.String keyStoreType)
This method returns the desired KeyStore object. |
javax.crypto.Mac |
getMac(AlgorithmID algorithm,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec paramSpec)
This method returns the desired MAC object. |
javax.crypto.Mac |
getMac(java.lang.String algorithm,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec paramSpec)
This method returns the desired MAC object. |
MaskGenerationAlgorithm |
getMaskGenerationAlgorithm(AlgorithmID algorithm)
This method returns the desired MaskGenerationAlgorithm object. |
java.security.MessageDigest |
getMessageDigest(AlgorithmID algorithm)
This method returns the desired MessageDigest object. |
java.security.MessageDigest |
getMessageDigest(java.lang.String algorithm)
This method returns the desired MessageDigest object. |
AlgorithmID[] |
getMicAlgs(java.lang.String micalg)
Returns an array of AlgorithmIDs specified by the given micalg String. |
java.security.PublicKey |
getOriginatorPublicKey(ASN1Object obj)
Decodes the OriginatorPublicKey from the given ASN1Object. |
OutputStreamCompressEngine |
getOutputStreamCompressEngine(AlgorithmID compressAlg,
java.io.OutputStream os,
int bufferSize)
Gets an OutputStreamCompressEngine for compressing data written to some output stream. |
OutputStreamHashEngine |
getOutputStreamHashEngine(AlgorithmID algorithm,
java.io.OutputStream os)
Returns an OutputStreamHashEngine for calculating the hash value on the data supplied from the given output stream. |
OutputStreamMacEngine |
getOutputStreamMacEngine(AlgorithmID algorithm,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec paramSpec,
java.io.OutputStream os)
Gets an OutputStreamMacEngine for calculating a Message Authentication Code on data written to some output stream. |
java.security.Key |
getPBEKey(char[] password,
AlgorithmID pbeAlg)
Creates secret key from the supplied password using the specified PBE algorithm. |
java.lang.String |
getProviderName()
Gets the name of the underlying cryptographic provider. |
javax.crypto.SecretKeyFactory |
getSecretKeyFactory(AlgorithmID algorithm)
Return a SecretKeyFactory for the requested algorithm. |
javax.crypto.SecretKeyFactory |
getSecretKeyFactory(java.lang.String algorithm)
Return a SecretKeyFactory for the requested algorithm. |
java.security.SecureRandom |
getSecureRandom()
Returns the random number generator. |
static SecurityProvider |
getSecurityProvider()
Returns the active SecurityProvider. |
java.security.Signature |
getSignature(AlgorithmID signatureAlgorithm,
int mode,
java.security.Key key)
This method returns the desired Signature object. |
java.security.Signature |
getSignature(AlgorithmID signatureAlgorithm,
int mode,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec paramSpec)
This method returns the desired Signature object. |
java.security.Signature |
getSignature(java.lang.String algorithm,
int mode,
java.security.Key key)
This method returns the desired Signature object. |
java.security.Signature |
getSignature(java.lang.String algorithm,
int mode,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec paramSpec)
This method returns the desired Signature object. |
static java.security.AlgorithmParameters |
getSignatureParameters(java.security.Signature signature)
Gets the parametes from a Signature engine. |
void |
setAEADMac(java.security.spec.AlgorithmParameterSpec paramSpec,
byte[] mac)
Sets the mac valus for the given AEAD AlgorithmParameterSpec. |
void |
setSecureRandom(java.security.SecureRandom random)
Sets the random number generator. |
static void |
setSecurityProvider(SecurityProvider provider)
Sets the global SecurityProvider. |
static void |
setSignatureParameters(java.security.Signature signature,
java.security.spec.AlgorithmParameterSpec paramSpec)
Sets the parameters for a Signature engine. |
javax.crypto.SecretKey |
unwrapKey(byte[] wrappedCek,
AlgorithmID kea,
java.security.Key kek,
java.security.AlgorithmParameters params,
java.lang.String cekAlgName)
Unwraps the given wrapped (encrypted) secret content encryption key for a KEKRecipientInfo or KeyAgreeRecipientInfo , or PasswordRecipientInfo . |
protected void |
validateDHPublicKey(javax.crypto.interfaces.DHPublicKey dhPublicKey)
Validates the given DHPublicKey. |
protected void |
validateKeyAgreementKey(java.security.PublicKey publicKey)
Validates the given public KeyAgrement key got from the other party. |
boolean |
verifySignatureFromHash(AlgorithmID signatureAlgorithm,
AlgorithmID digestAlgorithm,
java.security.PublicKey publicKey,
byte[] digest,
byte[] signatureValue)
Verifies the signature value of a CMS SignerInfo object with the given algorithm using the supplied public key. |
boolean |
verifySignatureFromSignedAttributes(AlgorithmID signatureAlgorithm,
AlgorithmID digestAlgorithm,
java.security.PublicKey publicKey,
byte[] signedAttributes,
byte[] signatureValue)
Verifies the signature value of a CMS SignerInfo calculated over the given signed attributes with the given algorithm using the supplied public key. |
byte[] |
wrapKey(javax.crypto.SecretKey cek,
AlgorithmID kea,
java.security.Key kek,
java.security.AlgorithmParameters params)
Wraps the given secret content encryption key for a KEKRecipientInfo or KeyAgreeRecipientInfo , or PasswordRecipientInfo . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SIGNATURE_NONE
public static final int SIGNATURE_SIGN
public static final int SIGNATURE_VERIFY
public static final int CIPHER_NONE
public static final int CIPHER_ENCRYPT
public static final int CIPHER_DECRYPT
public static final int CIPHER_WRAP
public static final int CIPHER_UNWRAP
public static final int COMPRESS
public static final int DECOMPRESS
public static final java.lang.String IMPLEMENTATION_NAME_DSA
SHA-1/DSA
. Implementation name of the DSA Signature engine
public static final java.lang.String IMPLEMENTATION_NAME_ECDSA
ECDSA
. Implementation name of the ECDSA Signature engine
public static final java.lang.String IMPLEMENTATION_NAME_ECDSA_PLAIN
ECDSAPlain
. Implementation name of the ECDSAPlain Signature engine.
The signature value is encoded as (r || s) and not wrapped into a SEQUENCE as done by X9.62;
see German BSI Technical Guideline TR-03111.
public static final java.lang.String IMPLEMENTATION_NAME_RSA_PSS
RSASSA-PSS
. Implementation name of the RSA-PSS Signature engine
public static final java.lang.String IMPLEMENTATION_NAME_RSA
RSA
. Implementation name of the RSA Cipher engine
public static final java.lang.String IMPLEMENTATION_NAME_RSA_OAEP
RSAES-OAEP
. Implementation name of the RSA-OAEP Cipher engine
public static final java.lang.String IMPLEMENTATION_NAME_PBKDF2
PBKDF2
. Implementation name of the PBKDF2 Cipher engine
public static final java.lang.String IMPLEMENTATION_NAME_PWRI_KEK
PWRI-KEK
. Implementation name of the PWRI-KEK Cipher engine
public static final java.lang.String ALG_DIGEST_MD5
MD5
. Used by the library with getMessageDigest()
.
public static final java.lang.String ALG_DIGEST_SHA
SHA
. Used by the library with getMessageDigest()
.
public static final java.lang.String ALG_HMAC_MD5
HmacMD5
. Used by the library with getMac()
.
public static final java.lang.String ALG_HMAC_SHA
HmacSHA1
. Used by the library with getMac()
.
public static final java.lang.String ALG_SIGNATURE_SHADSA
SHA1withDSA
. Used by the library with getSignature()
.
public static final java.lang.String ALG_SIGNATURE_RAWDSA
RawDSA
. Used by the library with getSignature()
.
public static final java.lang.String ALG_SIGNATURE_RAWECDSA
RawECDSA
. Used by the library with getSignature()
.
public static final java.lang.String ALG_SIGNATURE_RAWECDSA_PLAIN
RawECDSAPlain
. Used by the library with getSignature()
.
The signature value is encoded as (r || s) and not wrapped into a SEQUENCE as done by X9.62;
see German BSI Technical Guideline TR-03111.
public static final java.lang.String ALG_SIGNATURE_RAWRSAPSS
RawRSAPSS
. Used by this provider with getSignature()
.
public static final java.lang.String ALG_KEYEX_DH
DH
public static final java.lang.String ALG_KEYEX_ESDH
ESDH
public static final java.lang.String ALG_KEYEX_SSDH
SSDH
public static final java.lang.String ALG_CIPHER_RSA
RSA/ECB/PKCS1Padding
.
This string is NOT used with getCipher(), but it is the prefix of all RSA
algorithm identifier strings using PKCS#1v1.5 padding (see below). The different
identifiers were chosen to simplify using a particular RSA implementation just one
of these operations.
For example, to using a smartcard for RSA signing only one will
only care about signature creation operations and will want to leave all
other operations to the standard implementation. This can easily be done
by checking for the String ALG_CIPHER_RSA_SIGN
only.
If you write your own security provider that does nothing like this you will typically use code like:
if( algorithm.startsWith(ALG_CIPHER_RSA) ) { algorithm = ALG_CIPHER_RSA; } return Cipher.getInstance(algorithm, "MyProvider");
public static final java.lang.String ALG_CIPHER_RSA_SIGN
RSA/ECB/PKCS1Padding/Sign
.
Used by the library with getCipher()
to indicate an RSA signature creation operation (private key encryption).
public static final java.lang.String ALG_CIPHER_RSA_VERIFY
RSA/ECB/PKCS1Padding/Verify
.
Used by the library with getCipher()
to indicate an RSA signature verification operation (public key decryption).
public static final java.lang.String ALG_CIPHER_RSA_ENCRYPT
RSA/ECB/PKCS1Padding/Encrypt
.
Used by the library with getCipher()
to indicate an RSA data encryption operation (public key encryption).
public static final java.lang.String ALG_CIPHER_RSA_DECRYPT
RSA/ECB/PKCS1Padding/Decrypt
.
Used by the library with getCipher()
to indicate an RSA data decryption operation (private key decryption).
protected java.lang.String providerName_
protected java.security.Provider provider_
protected java.security.SecureRandom random_
Constructor Detail |
---|
public SecurityProvider()
public SecurityProvider(java.lang.String providerName)
providerName
- the name of the underlying cryptographic provider; if set,
anytime at first is tried to get an engine from this
cryptographic JCA/JCE provider.public SecurityProvider(java.security.Provider provider)
provider
- the underlying cryptographic provider; if set,
anytime at first is tried to get an engine from this
cryptographic JCA/JCE provider.Method Detail |
---|
public static SecurityProvider getSecurityProvider()
setSecurityProvider()
and the IAIK JCE
is available this will be the IaikProvider, otherwise it is an instance
of this class.
NOTE that the SecurityProvider setting is global.
Attention This method does not synchronize on the SecurityProvider setting.
If required, an application may take care for synchronizing itself
or may ensure to set
the security provider at
application startup.
public static void setSecurityProvider(SecurityProvider provider)
NOTE that the SecurityProvider setting is global.
Attention This method does not synchronize on the SecurityProvider setting. If required, an application may take care for synchronizing itself or may ensure to set the security provider at application startup.
provider
- the SecurityProvider which shall be usedpublic java.lang.String getProviderName()
null
if no cryptographic provider is setpublic java.security.MessageDigest getMessageDigest(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
algorithm
- the name of the requested digest algorithm
java.security.NoSuchAlgorithmException
- if no MessageDigest engine is available for
the requested algorithmpublic java.security.MessageDigest getMessageDigest(AlgorithmID algorithm) throws java.security.NoSuchAlgorithmException
algorithm
- the AlgorithmID of the requested digest algorithm
java.security.NoSuchAlgorithmException
- if no MessageDigest engine is available for
the requested algorithmpublic byte[] getHash(AlgorithmID algorithm, byte[] data) throws java.security.NoSuchAlgorithmException
algorithm
- the hash algorithm to be useddata
- the data on which the hash shall be calculated
java.security.NoSuchAlgorithmException
- if the requested hash algorithm is not supportedpublic InputStreamHashEngine getInputStreamHashEngine(AlgorithmID algorithm, java.io.InputStream is) throws java.security.NoSuchAlgorithmException
SignedDataStream
or DigestedDataStream
for obtaining
an InputStreamHashEngine
to which to pipe the
data to be hashed:
AlgorithmID hashAlgorithm = ...; InputStream is = ...; InputStreamHashEngine engine = securityProvider().getInputStreamHashEngine(hashAlgorithm, is); InputStream digestStream = engine.getInputStream(); ... // read the stream byte[] hash = engine.getHash();
algorithm
- the hash algorithm to be usedis
- the inputstream supplying the data to be hashed
java.security.NoSuchAlgorithmException
- if the requested algorithm is not supportedpublic InputStreamCipherEngine getInputStreamCipherEngine(AlgorithmID algorithm, int mode, java.security.Key key, java.security.AlgorithmParameters params) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
InputStreamCipherEngine
is used by class
EncryptedContentInfoStream
for content en/decryption.
The default implementation is based on the JCE javax.crypto.Cipher
engine
and uses a CipherInputStream
for en/decrypting the data that is read from
an underlying input stream.
algorithm
- the cipher algorithm to be usedmode
- the cipher mode to be used (CIPHER_NONE, CIPHER_ENCRYPT, CIPHER_DECRYPT, CIPHER_WRAP, or CIPHER_UNWRAP)key
- the key to be used for en/decipheringparams
- any algorithm parameters required by the cipher algorithm
java.security.NoSuchAlgorithmException
- if the requested cipher algorithm is not supported
java.security.InvalidKeyException
- if there is a key related problem
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid for the requested algorithmpublic InputStreamCipherEngine getInputStreamCipherEngine(AlgorithmID algorithm, int mode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
InputStreamCipherEngine
is used by class
EncryptedContentInfoStream
for content en/decryption.
The default implementation is based on the JCE javax.crypto.Cipher
engine
and uses a CipherInputStream
for en/decrypting the data that is read from
an underlying input stream.
algorithm
- the cipher algorithm to be usedmode
- the cipher mode to be used (CIPHER_NONE, CIPHER_ENCRYPT, CIPHER_DECRYPT, CIPHER_WRAP, or CIPHER_UNWRAP)key
- the key to be used for en/decipheringparams
- any algorithm parameters required by the cipher algorithm
java.security.NoSuchAlgorithmException
- if the requested cipher algorithm is not supported
java.security.InvalidKeyException
- if there is a key related problem
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid for the requested algorithmpublic ByteArrayCipherEngine getByteArrayCipherEngine(AlgorithmID algorithm, int mode, java.security.Key key, java.security.AlgorithmParameters params) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
ByteArrayCipherEngine
is used by class
EncryptedContentInfo
for content en/decryption.
The default implementation is based on the JCE javax.crypto.Cipher
engine
that en/decrypts data that is supplied by a byte array.
algorithm
- the cipher algorithm to be usedmode
- the cipher mode to be used (CIPHER_NONE, CIPHER_ENCRYPT, CIPHER_DECRYPT, CIPHER_WRAP, or CIPHER_UNWRAP)key
- the key to be used for en/decipheringparams
- any algorithm parameters required by the cipher algorithm
java.security.NoSuchAlgorithmException
- if the requested cipher algorithm is not supported
java.security.InvalidKeyException
- if there is a key related problem
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid for the requested algorithmpublic ByteArrayCipherEngine getByteArrayCipherEngine(AlgorithmID algorithm, int mode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
ByteArrayCipherEngine
is used by class
EncryptedContentInfo
for content en/decryption.
The default implementation is based on the JCE javax.crypto.Cipher
engine
that en/decrypts data that is supplied by a byte array.
algorithm
- the cipher algorithm to be usedmode
- the cipher mode to be used (CIPHER_NONE, CIPHER_ENCRYPT, CIPHER_DECRYPT, CIPHER_WRAP, or CIPHER_UNWRAP)key
- the key to be used for en/decipheringparams
- any algorithm parameters required by the cipher algorithm
java.security.NoSuchAlgorithmException
- if the requested cipher algorithm is not supported
java.security.InvalidKeyException
- if there is a key related problem
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid for the requested algorithmpublic InputStreamAuthCipherEngine getInputStreamAuthCipherEngine(AlgorithmID algorithm, int mode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, byte[] aad) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
InputStreamAuthCipherEngine
is used by class
EncryptedContentInfoStream
for authenticated content
en/decryption with CMS content-type AuthEnvelopedData
.
The default implementation is based on the JCE javax.crypto.Cipher
engine
and uses a CipherInputStream
for en/decrypting the data that is read from
an underlying input stream.
algorithm
- the content-authenticated encryption algorithm to be usedmode
- the cipher mode to be used (CIPHER_NONE, CIPHER_ENCRYPT, CIPHER_DECRYPT, CIPHER_WRAP, or CIPHER_UNWRAP)key
- the key to be used for en/decipheringparams
- any algorithm parameters required by the cipher algorithmaad
- the additional authenticated data (DER encoded authenticated
attributes from AuthEnvelopedData content type according to
RFC 5083), or null
if there are no authenticated
attributes or they are not available because we are in the parsing
phase where the authenticated attributes may not be accessible
at setup time because they are located behind the content
java.security.NoSuchAlgorithmException
- if the requested cipher algorithm is not supported
java.security.InvalidKeyException
- if there is a key related problem
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid for the requested algorithmpublic InputStreamAuthCipherEngine getInputStreamAuthCipherEngine(AlgorithmID algorithm, int mode, java.security.Key key, java.security.AlgorithmParameters params, byte[] aad) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
InputStreamAuthCipherEngine
is used by class
EncryptedContentInfoStream
for authenticated content
en/decryption with CMS content-type AuthEnvelopedData
.
The default implementation is based on the JCE javax.crypto.Cipher
engine
and uses a CipherInputStream
for en/decrypting the data that is read from
an underlying input stream.
algorithm
- the content-authenticated encryption algorithm to be usedmode
- the cipher mode to be used (CIPHER_NONE, CIPHER_ENCRYPT, CIPHER_DECRYPT, CIPHER_WRAP, or CIPHER_UNWRAP)key
- the key to be used for en/decipheringparams
- any algorithm parameters required by the cipher algorithmaad
- the additional authenticated data (DER encoded authenticated
attributes from AuthEnvelopedData content type according to
RFC 5083), or null
if there are no authenticated
attributes or they are not available because we are in the parsing
phase where the authenticated attributes may not be accessible
at setup time because they are located behind the content
java.security.NoSuchAlgorithmException
- if the requested cipher algorithm is not supported
java.security.InvalidKeyException
- if there is a key related problem
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid for the requested algorithmpublic ByteArrayAuthCipherEngine getByteArrayAuthCipherEngine(AlgorithmID algorithm, int mode, java.security.Key key, java.security.AlgorithmParameters params, byte[] aad) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
ByteArrayAuthCipherEngine
is used by class
EncryptedContentInfo
for authenicated content en/decryption
with CMS content-type AuthEnvelopedData
.
The default implementation is based on the JCE javax.crypto.Cipher
engine
that en/decrypts data that is supplied by a byte array.
algorithm
- the content-authenticated encryption algorithm to be usedmode
- the cipher mode to be used (CIPHER_NONE, CIPHER_ENCRYPT, CIPHER_DECRYPT, CIPHER_WRAP, or CIPHER_UNWRAP)key
- the key to be used for en/decipheringparams
- any algorithm parameters required by the cipher algorithmaad
- the additional authenticated data (DER encoded authenticated
attributes from AuthEnvelopedData content type according to
RFC 5083), or null
if there are no authenticated
attributes
java.security.NoSuchAlgorithmException
- if the requested cipher algorithm is not supported
java.security.InvalidKeyException
- if there is a key related problem
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid for the requested algorithmpublic ByteArrayAuthCipherEngine getByteArrayAuthCipherEngine(AlgorithmID algorithm, int mode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, byte[] aad) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
ByteArrayCipherEngine
is used by class
EncryptedContentInfo
for authenicated
content en/decryption with CMS content-type AuthEnvelopedData
.
The default implementation is based on the JCE javax.crypto.Cipher
engine
that en/decrypts data that is supplied by a byte array.
algorithm
- the content-authenticated encryption algorithm to be usedmode
- the cipher mode to be used (CIPHER_NONE, CIPHER_ENCRYPT, CIPHER_DECRYPT, CIPHER_WRAP, or CIPHER_UNWRAP)key
- the key to be used for en/decipheringparams
- any algorithm parameters required by the cipher algorithmaad
- the additional authenticated data (DER encoded authenticated
attributes from AuthEnvelopedData content type according to
RFC 5083), or null
if there are no authenticated
attributes
java.security.NoSuchAlgorithmException
- if the requested cipher algorithm is not supported
java.security.InvalidKeyException
- if there is a key related problem
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid for the requested algorithmpublic AuthCipherEngine getAuthCipherEngine(AlgorithmID algorithm, int mode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, byte[] aad) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
AuthCipherEngine
is used by class
EncryptedContentInfoOutputStream
for
authenticated content encryption with CMS content-type AuthEnvelopedData
.
algorithm
- the content-authenticated encryption algorithm to be usedmode
- the cipher mode to be used (CIPHER_NONE, CIPHER_ENCRYPT, CIPHER_DECRYPT, CIPHER_WRAP, or CIPHER_UNWRAP)key
- the key to be used for en/decipheringparams
- any algorithm parameters required by the cipher algorithmaad
- the additional authenticated data (DER encoded authenticated
attributes from AuthEnvelopedData content type according to
RFC 5083), or null
if there are no authenticated
attributes or they are not available because we are in the parsing
phase where the authenticated attributes may not be accessible
at setup time because they are located behind the content
java.security.NoSuchAlgorithmException
- if the requested cipher algorithm is not supported
java.security.InvalidKeyException
- if there is a key related problem
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid for the requested algorithmpublic AuthCipherEngine getAuthCipherEngine(AlgorithmID algorithm, int mode, java.security.Key key, java.security.AlgorithmParameters params, byte[] aad) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
AuthCipherEngine
is used by class
EncryptedContentInfoOutputStream
for
authenticated content encryption with CMS content-type AuthEnvelopedData
.
algorithm
- the content-authenticated encryption algorithm to be usedmode
- the cipher mode to be used (CIPHER_NONE, CIPHER_ENCRYPT, CIPHER_DECRYPT, CIPHER_WRAP, or CIPHER_UNWRAP)key
- the key to be used for en/decipheringparams
- any algorithm parameters required by the cipher algorithmaad
- the additional authenticated data (DER encoded authenticated
attributes from AuthEnvelopedData content type according to
RFC 5083), or null
if there are no authenticated
attributes or they are not available because we are in the parsing
phase where the authenticated attributes may not be accessible
at setup time because they are located behind the content
java.security.NoSuchAlgorithmException
- if the requested cipher algorithm is not supported
java.security.InvalidKeyException
- if there is a key related problem
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid for the requested algorithmpublic OutputStreamHashEngine getOutputStreamHashEngine(AlgorithmID algorithm, java.io.OutputStream os) throws java.security.NoSuchAlgorithmException
OutputStreamHashEngine
to which to pipe the
data to be hashed:
AlgorithmID hashAlgorithm = ...; OutputStream is = ...; OutputStreamHashEngine engine = securityProvider().getOutputStreamHashEngine(hashAlgorithm, is); OutputStream digestStream = engine.getOutputStream(); ... // read the stream byte[] hash = engine.getHash();
algorithm
- the hash algorithm to be usedos
- the outputstream to which the data to be hashed is written
java.security.NoSuchAlgorithmException
- if the requested algorithm is not supportedpublic InputStreamCompressEngine getInputStreamCompressEngine(AlgorithmID compressAlg, java.io.InputStream is, int compressionMode, int bufferSize) throws java.security.NoSuchAlgorithmException
InputStreamCompressEngine
is used by class
CompressedDataStream
for content compression/decompression.
This class provides an implementation of the ZLIB compression algorithm ([RFC1950]
[RFC1951]) based on the Deflater/Inflater utilities of the java.utils.zip
package.
compressAlg
- the compression/decompression algorithm to be usedis
- the input stream supplying the data to be compressed/decompressedcompressionMode
- the compression mode to be used (COMPRESS
or DECOMPRESS
)bufferSize
- the size of the internal buffer, if used by the compress engine (will be
the blockSize value used for the compressed data encoding); maybe -1,
if no block encoding is used; in this case the engine may use a default buffer size
java.security.NoSuchAlgorithmException
- if the requested compression algorithm is not supportedpublic OutputStreamCompressEngine getOutputStreamCompressEngine(AlgorithmID compressAlg, java.io.OutputStream os, int bufferSize) throws java.security.NoSuchAlgorithmException
OutputStreamCompressEngine
is used by class
CompressedDataOutputStream
for content compression.
This class provides an implementation of the ZLIB compression algorithm ([RFC1950]
[RFC1951]) based on the Deflater utilities of the java.utils.zip
package.
compressAlg
- the compression algorithm to be usedos
- the output stream to which to write the data to be compressedbufferSize
- the size of the internal buffer, if used by the compress engine (will be
the blockSize value used for the compressed data encoding); maybe -1,
if no block encoding is used; in this case the engine may use a default buffer size
java.security.NoSuchAlgorithmException
- if the requested compression algorithm is not supportedpublic byte[] compress(AlgorithmID compressAlg, byte[] data, int compressionMode) throws java.security.NoSuchAlgorithmException, java.io.IOException
java.utils.zip
package.
compressAlg
- the compression/decompression algorithm to be useddata
- the input data to be compressed/decompressedcompressionMode
- the compression mode to be used (COMPRESS
or DECOMPRESS
)
IOExecption
- if an I/O error occurs during data compression/decompression
java.security.NoSuchAlgorithmException
- if the requested compression algorithm is not supported
java.io.IOException
public javax.crypto.Mac getMac(java.lang.String algorithm, java.security.Key key, java.security.spec.AlgorithmParameterSpec paramSpec) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException
algorithm
- the name of the Mac algorithmkey
- the key, if not null to be used for initializing the Mac objectparamSpec
- any parameters, if not null to be used for initializing the Mac object
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid
java.security.InvalidKeyException
- if the key is not valid
java.security.NoSuchAlgorithmException
- if no Mac engine is available for the requested algorithmpublic javax.crypto.Mac getMac(AlgorithmID algorithm, java.security.Key key, java.security.spec.AlgorithmParameterSpec paramSpec) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException
algorithm
- the name of the Mac algorithmkey
- the key, if not null to be used for initializing the Mac objectparamSpec
- any parameters, if not null to be used for initializing the Mac object
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid
java.security.InvalidKeyException
- if the key is not valid
java.security.NoSuchAlgorithmException
- if no Mac engine is available for the requested algorithmpublic InputStreamMacEngine getInputStreamMacEngine(AlgorithmID algorithm, java.security.Key key, java.security.spec.AlgorithmParameterSpec paramSpec, java.io.InputStream is) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException
InputStreamMacEngine
is used by class AuthenticatedDataStream
for
content MAC calculation.
The default implementation is based on the JCA javax.crypto.Mac
engine.
algorithm
- the name of the Mac algorithmkey
- the key, if not null to be used for initializing the Mac objectparamSpec
- any parameters to be used for initializing the Mac object; maybe null
is
- the input stream supplying the data to be processed
java.security.InvalidKeyException
- if the key is not valid
java.security.NoSuchAlgorithmException
- if no Mac engine is available for the requested algorithm
java.security.InvalidAlgorithmParameterException
- if the parameters are not validpublic OutputStreamMacEngine getOutputStreamMacEngine(AlgorithmID algorithm, java.security.Key key, java.security.spec.AlgorithmParameterSpec paramSpec, java.io.OutputStream os) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException
OutputStreamMacEngine
is used by class AuthenticatedDataOutputStream
for
content MAC calculation.
The default implementation is based on the JCA javax.crypto.Mac
engine.
algorithm
- the name of the Mac algorithmkey
- the key, if not null to be used for initializing the Mac objectparamSpec
- any parameters to be used for initializing the Mac object; maybe null
os
- the output stream to which the data to be processed is written
java.security.InvalidKeyException
- if the key is not valid
java.security.NoSuchAlgorithmException
- if no Mac engine is available for the requested algorithm
java.security.InvalidAlgorithmParameterException
- if the parameters are not validpublic byte[] calculateMac(AlgorithmID algorithmID, java.security.Key key, java.security.spec.AlgorithmParameterSpec paramSpec, byte[] data) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException
algorithmID
- the id of the Mac algorithmkey
- the key to be used for initializing the Mac objectparamSpec
- any parameters, if not null to be used for initializing the Mac objectdata
- the data from which to calculate the MAC
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid
java.security.InvalidKeyException
- if the key is not valid
java.security.NoSuchAlgorithmException
- if no Mac engine is available for the requested algorithmpublic 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.
algorithm
- the name of the Signature algorithmmode
- the mode indicating if the engine has to be initializedkey
- the key for initializing the Signature engine
java.security.InvalidKeyException
- if the key is not valid
java.security.NoSuchAlgorithmException
- if no Signature engine is
available for the requested algorithmpublic java.security.Signature getSignature(java.lang.String algorithm, int mode, java.security.Key key, java.security.spec.AlgorithmParameterSpec paramSpec) 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.
If algorithm parameters are specified they are set for the
Signature engine.
algorithm
- the name of the Signature algorithmmode
- the mode indicating if the engine has to be initializedkey
- the key for initializing the Signature engineparamSpec
- any parameters to be set for the Signature engine, if not null
java.security.InvalidKeyException
- if the key is not valid
java.security.NoSuchAlgorithmException
- if no Signature engine is
available for the requested algorithmpublic java.security.Signature getSignature(AlgorithmID signatureAlgorithm, int mode, java.security.Key key) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmException
SIGNATURE_SIGN
or
SIGNATURE_VERIFY
the signature object is to be
initialized with the provided key in the respective mode.
signatureAlgorithm
- the AlgorithmID of the Signature algorithmmode
- the mode indicating if the engine has to be initializedkey
- the key for initializing the Signature engine
java.security.InvalidKeyException
- if the key is not valid
java.security.NoSuchAlgorithmException
- if no Signature engine is
available for the requested algorithmpublic java.security.Signature getSignature(AlgorithmID signatureAlgorithm, int mode, java.security.Key key, java.security.spec.AlgorithmParameterSpec paramSpec) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmException
SIGNATURE_SIGN
or
SIGNATURE_VERIFY
the signature object is to be
initialized with the provided key in the respective mode.
If algorithm parameters are specified they are set for the
Signature engine.
signatureAlgorithm
- the AlgorithmID of the Signature algorithmmode
- the mode indicating if the engine has to be initializedkey
- the key for initializing the Signature engineparamSpec
- any parameters to be set for the Signature engine, if not null
java.security.InvalidKeyException
- if the key is not valid
java.security.NoSuchAlgorithmException
- if no Signature engine is
available for the requested algorithmpublic static void setSignatureParameters(java.security.Signature signature, java.security.spec.AlgorithmParameterSpec paramSpec)
Signature.setParameter(AlgorithmParameterSpec paramSpec)
for JDK versions > 1.2, and Signature.setParameter(String param, Object value)
(via reflection) for JDK 1.2.
signature
- the Signature engine for which to set the parametersparamSpec
- the parameters to be set
java.security.InvalidParameterException
- if the parameters cannot be set (e.g. if the given
paramSpec is not suiteable for the given Signature engine)public static java.security.AlgorithmParameters getSignatureParameters(java.security.Signature signature)
Signature.GetParameters()
for JDK versions > 1.2, and Signature.getParameter(String param)
(via reflection) for JDK 1.3.
signature
- the Signature engine from which to get the parameters
null
if no parameters are includedpublic javax.crypto.KeyAgreement getKeyAgreement(AlgorithmID keyAgreementAlgorithm, java.security.Key key, java.security.spec.AlgorithmParameterSpec paramSpec) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException, java.security.NoSuchAlgorithmException
keyAgreementAlgorithm
- the algorithmID of the key agreement algorithm requestedkey
- the (private) key for initializing the KeyAgreementparamSpec
- any parameters used for intializing the key agreement
java.security.InvalidKeyException
- if the key is not valid
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid
java.security.NoSuchAlgorithmException
- if no KeyAgreement engine is available
for the requested algorithmpublic byte[] calculateSharedSecret(AlgorithmID keyAgreementAlgorithm, java.security.Key key, java.security.Key otherKey, java.security.spec.AlgorithmParameterSpec paramSpec) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException, java.security.NoSuchAlgorithmException
keyAgreementAlgorithm
- the algorithmID of the key agreement algorithm requestedkey
- the (private) key for initializing the KeyAgreementotherKey
- the (public) key from the other partyparamSpec
- any parameters used for intializing the key agreement
java.security.InvalidKeyException
- if the key is not valid
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid
java.security.NoSuchAlgorithmException
- if no KeyAgreement engine is available
for the requested algorithmpublic byte[] calculateSignatureFromSignedAttributes(AlgorithmID signatureAlgorithm, 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.
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 calculated
java.security.NoSuchAlgorithmException
- if no Signature engine is available for the requested algorithm
java.security.InvalidKeyException
- if the key is not valid
if
- signature calculation fails
java.security.SignatureException
public byte[] calculateSignatureFromHash(AlgorithmID signatureAlgorithm, 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).
signatureAlgorithm
- signatureAlgorithm the signature algorithm to be
used, e.g. rsaEncryption, DSAdigestAlgorithm
- the digest algorithm 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 smartcardsdigest
- the digest value over which the signature shall be calculated
java.security.NoSuchAlgorithmException
- if any of the required algorithms is not supported
java.security.InvalidKeyException
- if the key is not valid
java.security.SignatureException
- if signature calculation failspublic boolean verifySignatureFromSignedAttributes(AlgorithmID signatureAlgorithm, AlgorithmID digestAlgorithm, java.security.PublicKey publicKey, byte[] signedAttributes, byte[] signatureValue) 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
verifying the signature when no 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. Although generally for public key operations
smartcards may not be used, 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 verification (including
any digest calculation required).
Since this method requires to calculate the digest value over the DER encoded signed attributes as part of the signature verification, it uses a oridinary JCA Signature engine.
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);publicKey
- the public key of the signersignedAttributes
- the DER encoding of the signed attributes over which
the signature has been calculatedsignatureValue
- the signatureValue the signature value to be verified
true
if the signature is ok, false
if not
java.security.NoSuchAlgorithmException
- if any of the required algorithms is not supported
java.security.InvalidKeyException
- if the key is not valid
java.security.SignatureException
- if signature verification fails because of some computation errorpublic boolean verifySignatureFromHash(AlgorithmID signatureAlgorithm, AlgorithmID digestAlgorithm, java.security.PublicKey publicKey, byte[] digest, byte[] signatureValue) 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
verifying the signature when no signed attributes are present. Since
the data to be verified may be of arbitrary size this method expects the
already hashed data to only be verified against the signature value.
For that reason, when writing your own SecurityProvider and overriding this method, you will need some kind of RAW signature (respectively "encrypted digest decryption") mechanism only expecting the already hashed data (e.g. a "RawDSA" signature engine when using DSA repectively a Cipher engine when using RSA).
Although generally for public key operations smartcards may not be used,
when overriding this method for use with smartcards, please be sure
that your smartcard is able to do the signature verification 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 verifySignatureFromSignedAttributes
for verifying the signature calculated from the DER encoding of the signed
attributes (thereby doing the hash computation, too).
signatureAlgorithm
- signatureAlgorithm the signature algorithm to be
used for verification, e.g. rsaEncryption, DSAdigestAlgorithm
- the digest algorithm that has been used for hash
computation (e.g. SHA-1, ..., SHA-512); may be necessary for some signature
schemes (e.g. to be check against a DigestInfo in a PKCS#1 RSA signature)publicKey
- the public key of the signerdigest
- the digest value to be verified
true
if the signature is ok, false
if not
java.security.NoSuchAlgorithmException
- if any of the required algorithms is not supported
java.security.InvalidKeyException
- if the key is not valid
java.security.SignatureException
- if signature verification fails because
of some crypto related or parsing errorpublic byte[] encryptKey(javax.crypto.SecretKey cek, AlgorithmID kea, java.security.PublicKey recipientKey) 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
encrypting the key. If another algorithm than RSA is requested, this
method throws a NoSuchAlgorithmException. An application wishing to
support another algorithm may override this method.
cek
- the secret content encryption key to be encryptedkea
- the key encryption alglorithm to be used, e.g. rsaEncryptionrecipientKey
- the public key of the recipient to be used for encrypting
content encryption key
java.security.NoSuchAlgorithmException
- if the requested algorithm is not available
java.security.InvalidKeyException
- if the encryption key is not valid
javax.crypto.NoSuchPaddingException
- if the required padding scheme is not supported
javax.crypto.BadPaddingException
- if an padding error occurspublic javax.crypto.SecretKey decryptKey(byte[] encryptedKey, AlgorithmID kea, java.security.PrivateKey recipientKey) 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.
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 key
java.security.NoSuchAlgorithmException
- if the requested algorithm is not available
java.security.InvalidKeyException
- if the decryption key is not valid
javax.crypto.NoSuchPaddingException
- if the required padding scheme is not supported
javax.crypto.BadPaddingException
- if an padding error occurspublic javax.crypto.SecretKey decryptKey(byte[] encryptedKey, 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.
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. "AES") to be set for the
SecretKey object created by this method
java.security.NoSuchAlgorithmException
- if the requested algorithm is not available
java.security.InvalidKeyException
- if the decryption key is not valid
javax.crypto.NoSuchPaddingException
- if the required padding scheme is not supported
javax.crypto.BadPaddingException
- if an padding error occurspublic javax.crypto.Cipher getCipher(java.lang.String algorithm, int mode, java.security.Key key, java.security.AlgorithmParameters params) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
The symmetric ciphers shall explain themselves.
RSA/ECB/PKCS1Padding means RSA en/decryption with padding as defined in PKCS#1 1.5 where the padding block type is automatically selected based on the type of key used (block type 1 for signature operations, block type 2 for encryption operations). This cipher will be always used the same way (other methods need not to be implemented!):
Cipher rsa = provider.getCipher("RSA/ECB/PKCS1Padding/...", ...); crypted = rsa.doFinal(plain);If the mode parameter is
CIPHER_ENCRYPT
, CIPHER_WRAP
CIPHER_DECRYPT
, or CIPHER_UNWRAP
the cipher object
has to be initialized with the provided key in the respective mode.
algorithm
- the name of the requested algorithmmode
- the mode indicating if the Cipher has to be initializedkey
- the key to be used for initializing the cipherparams
- the parameters to be used to initialize the cipher
java.security.NoSuchAlgorithmException
- if no Cipher engine is available for the
requested algorithm
java.security.InvalidKeyException
- if the key is not valid
java.security.InvalidAlgorithmParameterException
- if the parameters are not validpublic javax.crypto.Cipher getCipher(java.lang.String algorithm, int mode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
The symmetric ciphers shall explain themselves.
RSA/ECB/PKCS1Padding means RSA en/decryption with padding as defined in PKCS#1 1.5 where the padding block type is automatically selected based on the type of key used (block type 1 for signature operations, block type 2 for encryption operations). This cipher will be always used the same way (other methods need not to be implemented!):
Cipher rsa = provider.getCipher("RSA/ECB/PKCS1Padding/...", ...); crypted = rsa.doFinal(plain);If the mode parameter is
CIPHER_ENCRYPT
, CIPHER_WRAP
CIPHER_DECRYPT
, or CIPHER_UNWRAP
the cipher object
has to be initialized with the provided key in the respective mode.
algorithm
- the name of the requested algorithmmode
- the mode indicating if the Cipher has to be initializedkey
- the key to be used for initializing the cipherparams
- the parameters to be used to initialize the cipher
java.security.NoSuchAlgorithmException
- if no Cipher engine is available for the
requested algorithm
java.security.InvalidKeyException
- if the key is not valid
java.security.InvalidAlgorithmParameterException
- if the parameters are not validpublic javax.crypto.Cipher getCipher(AlgorithmID algorithm, int mode, java.security.Key key, java.security.AlgorithmParameters params) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
If the mode parameter is CIPHER_ENCRYPT
, CIPEHER_WRAP
,
CIPHER_DECRYPT
or CIPHER_UNWRAP
the cipher object is to be
initialized with the provided key and parameters in the respective mode.
If initializing the cipher for encryption/wrapping any parameters used for initializing or produced by the Cipher engine have to be included in the supplied algorithmID, e.g.:
if ((mode == CIPHER_ENCRYPT) || (mode == CIPHER_WRAP)) { AlgorithmParameters parameters = cipher.getParameters(); if (parameters != null) { algorithm.setAlgorithmParameters(parameters); } }Since
getParameters
may not be implemented by some particular
provider, in this case this methods looks if the cipher produced an IV
and includes it into the AlgorithmID (however, only if the AlgorithmID
yet does not include parameters):
if ((mode == CIPHER_ENCRYPT) || (mode == CIPHER_WRAP)) { // any parameters to set for the AlgorithmID? AlgorithmParameters parameters = cipher.getParameters(); if (parameters != null) { algorithm.setAlgorithmParameters(parameters); } else { if (algorithm.getParameter() == null) { if (params != null) { algorithm.setAlgorithmParameters(params); } else { // iv? byte[] iv = cipher.getIV(); if (iv != null) { algorithm.setParameter(new OCTET_STRING(iv)); } } } } }
algorithm
- the algorithm for which to create a Cipher enginemode
- the Cipher mode (CIPHER_ENCRYPT, CIPHER_WRAP, CIPHER_DECRYPT, CIPHER_UNWRAP)key
- the key to be used for initializing the cipherparams
- any algorithm parameters used for initializing the cipher
java.security.NoSuchAlgorithmException
- if no Cipher engine is available for the
requested algorithm
java.security.InvalidKeyException
- if the key is not valid
java.security.InvalidAlgorithmParameterException
- if the parameters are not validpublic javax.crypto.Cipher getCipher(AlgorithmID algorithm, int mode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
If the mode parameter is CIPHER_ENCRYPT
, CIPEHER_WRAP
,
CIPHER_DECRYPT
or CIPHER_UNWRAP
the cipher object is to be
initialized with the provided key and parameters in the respective mode.
If initializing the cipher for encryption/wrapping any parameters used for initializing or produced by the Cipher engine have to be included in the supplied algorithmID, e.g.:
if ((mode == CIPHER_ENCRYPT) || (mode == CIPHER_WRAP)) { AlgorithmParameters parameters = cipher.getParameters(); if (parameters != null) { algorithm.setAlgorithmParameters(parameters); } }Since
getParameters
may not be implemented by some particular
provider, in this case this methods looks if the cipher produced an IV
and includes it into the AlgorithmID (however, only if the AlgorithmID
yet does not include parameters):
if ((mode == CIPHER_ENCRYPT) || (mode == CIPHER_WRAP)) { // any parameters to set for the AlgorithmID? AlgorithmParameters parameters = cipher.getParameters(); if (parameters != null) { algorithm.setAlgorithmParameters(parameters); } else { if (algorithm.getParameter() == null) { // iv? byte[] iv = cipher.getIV(); if (iv != null) { algorithm.setParameter(new OCTET_STRING(iv)); } } } }
algorithm
- the algorithm for which to create a Cipher enginemode
- the Cipher mode (CIPHER_ENCRYPT, CIPHER_WRAP, CIPHER_DECRYPT, CIPHER_UNWRAP)key
- the key to be used for initializing the cipherparams
- any algorithm parameters used for initializing the cipher
java.security.NoSuchAlgorithmException
- if no Cipher engine is available for the
requested algorithm
java.security.InvalidKeyException
- if the key is not valid
java.security.InvalidAlgorithmParameterException
- if the parameters are not validpublic java.security.KeyPairGenerator getKeyPairGenerator(AlgorithmID algorithm) throws java.security.NoSuchAlgorithmException
algorithm
- the requested algorithm
NoSuchSuchAlgorithmException
- if no KeyPairGenerator for the requested
algorithm is available
java.security.NoSuchAlgorithmException
public javax.crypto.KeyGenerator getKeyGenerator(AlgorithmID algorithm, int keyLength) throws java.security.NoSuchAlgorithmException
algorithm
- the requested algorithmkeyLength
- the length of the key to be generated, may be required for
algorithms with variable key size; -1 if the KeyGenerator
should generate a key of default length
NoSuchSuchAlgorithmException
- if no KeyGenerator for the requested
algorithm is available
java.security.NoSuchAlgorithmException
public javax.crypto.KeyGenerator getKeyGenerator(AlgorithmID algorithm, java.security.spec.AlgorithmParameterSpec paramSpec) throws java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException
algorithm
- the requested algorithmparamSpec
- any parameters for initializing the key generator
NoSuchSuchAlgorithmException
- if no KeyGenerator for the requested
algorithm is available
java.security.InvalidAlgorithmParameterException
- if the parameters are invalid
or not suitable for the requested KeyGenerator
java.security.NoSuchAlgorithmException
public javax.crypto.KeyGenerator getKeyGenerator(java.lang.String algorithm, int keyLength) throws java.security.NoSuchAlgorithmException
algorithm
- the requested algorithmkeyLength
- the length for initializing the key generator;
-1 if using the default length
NoSuchSuchAlgorithmException
- if no KeyGenerator for the requested
algorithm is available
java.security.NoSuchAlgorithmException
public javax.crypto.SecretKey generateKey(AlgorithmID algorithm, java.security.spec.AlgorithmParameterSpec paramSpec) throws java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException
algorithm
- the requested algorithmparamSpec
- any parameters for initializing the key generator
NoSuchSuchAlgorithmException
- if the key for the requested
algorithm cannot be created
java.security.InvalidAlgorithmParameterException
- if the parameters are invalid
or not suitable for the requested Key
java.security.NoSuchAlgorithmException
public javax.crypto.SecretKey generateKey(AlgorithmID algorithm, int keyLength) throws java.security.NoSuchAlgorithmException
algorithm
- the requested algorithmkeyLength
- the length of the key to be generated, may be required for
algorithms with variable key size
NoSuchSuchAlgorithmException
- if the key for the requested
algorithm cannot be created
java.security.NoSuchAlgorithmException
public javax.crypto.SecretKeyFactory getSecretKeyFactory(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
algorithm
- the requested algorithm
NoSuchSuchAlgorithmException
- if no SecretKeyFactory for the requested
algorithm is available
java.security.NoSuchAlgorithmException
public javax.crypto.SecretKeyFactory getSecretKeyFactory(AlgorithmID algorithm) throws java.security.NoSuchAlgorithmException
algorithm
- the requested algorithm
NoSuchSuchAlgorithmException
- if no KeyGenerator for the requested
algorithm is available
java.security.NoSuchAlgorithmException
public java.security.KeyFactory getKeyFactory(AlgorithmID algorithm) throws java.security.NoSuchAlgorithmException
algorithm
- the name of the algorithm for which to get a KeyFactory
java.security.NoSuchAlgorithmException
- if no KeyFactory is available for the
requested algorithmpublic byte[] wrapKey(javax.crypto.SecretKey cek, AlgorithmID kea, java.security.Key kek, java.security.AlgorithmParameters params) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
KEKRecipientInfo
or KeyAgreeRecipientInfo
, or PasswordRecipientInfo
.
The given secret content encryption key is wrapped by encrypting it
with the given secret key encryption key using the requested
key encryption algorithm. If algorithm parameters are supplied they
are used for initializing the key encryption cipher.
Attention: If algorithm parameters are to be used (or
produced by the cipher) this method has to include them into
the parameters field of the supplied key encryption AlgorithmID, too
(this only may work if the Cipher engine supports method
getParameters
.
cek
- the secret content encryption key to be wrapped (encrypted)kea
- the key wrap (encryption) alglorithm to be used, e.g. AESWrapkek
- the key encryption key to be used for encrypting the content
encryption keyparams
- any algorithm parameters required for initializing the
key encryption cipher
java.security.NoSuchAlgorithmException
- if the requested algorithm is not available
java.security.InvalidKeyException
- if the key encryption key is not valid
java.security.InvalidAlgorithmParameterException
- if the parameters are not valid
javax.crypto.IllegalBlockSizeException
- if the block size is not correct
javax.crypto.BadPaddingException
- if an padding error occurspublic javax.crypto.SecretKey unwrapKey(byte[] wrappedCek, AlgorithmID kea, java.security.Key kek, java.security.AlgorithmParameters params, java.lang.String cekAlgName) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
KEKRecipientInfo
or KeyAgreeRecipientInfo
, or PasswordRecipientInfo
.
The given wrapped secret content encryption key is unwrapped by decrypting it with the given secret key encryption key using the requested key encryption algorithm. If algorithm parameters are supplied they are used for initializing the key (un)wrapping cipher.
wrappedCek
- the wrapped secret content encryption key to be unwrapped (decrypted)kea
- the key (un)wrap (en/decryption) alglorithm to be used, e.g. AESWrapkek
- the key encryption key to be used for decrypting the encrypted content
encryption keyparams
- any algorithm parameters required for initializing the ciphercekAlgName
- the name of the content encryption cipher (required by
the unwrap
method of a JCE cipher engine)
java.security.NoSuchAlgorithmException
- if the requested algorithm is not available
java.security.InvalidKeyException
- if the key encryption key is not valid
java.security.InvalidAlgorithmParameterException
- if the parameters are not validpublic javax.crypto.SecretKey createSharedKeyEncryptionKey(AlgorithmID keyAgreeAlg, java.security.PrivateKey myKey, java.security.PublicKey otherKey, AlgorithmID kea, int kekLength, byte[] ukm, java.lang.String kekName) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
Creating a shared key encryption key is required when a key agreement algorithm
is used as key management protocol for the recipient of an EnvelopedData or
AuthenticatedData object. The shared key encryption key will be used by an
KeyAgreeRecipientInfo
to encrypt
the secret content encryption key or Mac key.
Attention: This method ALWAYS throws an exception since there is no general
way for initializing a ESDH KeyAgreement with an IAIK ESDHKEKParameterSpec (representing
the RFC2631 OtherInfo). When using a different provider than IAIK this method has to be
overriden to create the shared key! For the IAIK cryptography provider this method is
overriden
for ESDH key agreement.
keyAgreeAlg
- the key agreement algorithmmyKey
- the private key agreement key of the one partyotherKey
- the public key agreement key of the other partykea
- the key ancryption algorithm (may be required for kek generation)kekLength
- the length of the shared key encryption key to be generatedukm
- any user keying material that may be required for kek generationkekName
- the name of the key encryption algorithm
java.security.NoSuchAlgorithmException
- if the requested algorithm is not available
java.security.InvalidKeyException
- if there is a key related problem
java.security.InvalidAlgorithmParameterException
- if the parameters are invalidpublic void checkDomainParameters(java.security.PrivateKey myKey, java.security.PublicKey otherKey) throws java.security.InvalidParameterException
Only for DH key agreement there is a general way to access the parameters of
DH keys through the JCE API. CMS, however, per default uses ephemeral static
DH (ESDH) (EnvelopedData, AuthenticatedData). For also supporting ESDH in a
general way this method tries to get the parameters from the key Algorithm IDs
and compares their encodings if the supplied keys are not standard JCE DH keys.
Since this proceeding involves some encoding - decoding overhead, it might be
appropriate to override this method for an ESDH supporting provider (as done
for IAIK by the IaikProvider
.
myKey
- the private key of the first partyotherKey
- the public key of the other party
InvalidParameterEyception
- if domain parameters are included
in both keys, but the domain parameters do not match
java.security.InvalidParameterException
public java.security.KeyPair generateKeyAgreementKeyPair(AlgorithmID keyAgreeAlgorithm, java.security.PublicKey otherKey) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
overriden
for (ES)DH key agreement methods to use its (ES)DH KeyPairGenerator
witch can be initialized with the parameters of the public key of the other party.
This method is called by the library for creating the originator key pair if
the OriginatorPublicKey
alternative is used
for representing the public key of the originator within a KeyAgreeRecipientInfo
. The public key supplied
to this method is the one of the recipient and the key pair returned by this
method must have domain parameters matching to those of the given recipient public
key. Note that ephemeral static Diffie Hellmean (ESDH) is the default key
agreement method used by the CMS types EnvelopedData
and
AuthenticatedData
. According RFC 5652 the
OriginatorPublicKey
has to be used for representing the public
key of the originator if ESDH is used as key agreement algorithm.
keyAgreeAlgorithm
- the key agreement algorithm to be usedotherKey
- the public key of the other party
java.security.NoSuchAlgorithmException
- if the requested algorithm is not available
java.security.InvalidKeyException
- if the key is not appropriate for the key agreement algorithm
java.security.InvalidAlgorithmParameterException
- if the parameters are invalidprotected void validateKeyAgreementKey(java.security.PublicKey publicKey) throws java.security.InvalidKeyException
null
)
is in the interval [2,p-2] (see RFC 7919, 5.2; RFC 2631, 2.1.5).
No check is done for other keys since they may require a JCA provider specific handling. An application may override this method for provider-specific checking a key agreement key.
publicKey
- the public key
java.security.InvalidKeyException
- if the given key is supposed to be a not valid keyprotected void validateDHPublicKey(javax.crypto.interfaces.DHPublicKey dhPublicKey) throws java.security.InvalidKeyException
null
)
is in the interval [2,p-2] (see RFC 7919, 5.2; RFC 2631, 2.1.5).
dhPublicKey
- the DH public key
java.security.InvalidKeyException
- if the DH key is supposed to be a weak keypublic ASN1Object getASN1OriginatorPublicKey(java.security.PublicKey originatorPublicKey) throws CMSException
For some key agree algorithms CMS may require a special key encoding for the KeyAgreeRecipientInfo
OriginatorPublicKey
choice. According to
RFC 3370 (Cryptographic Message Syntax Algorithms), ESDH public keys have to
be encoded with absent parameters in their AlgorithmID field when encoded as originator
public keys:
The originatorKey algorithm field MUST contain the dh-public-number object identifier with absent parameters. The originatorKey publicKey field MUST contain the ephemeral public key of the sender.This method tries to get an ASN.1 representation of the suppiled originator public key. Since it only can handle keys in a general way it simple calls
DerCoder.decode(originatorPublicKey.getEncoded());An application may override this method to handle keys in a provider-specific manner.
originatorPublicKey
- the originator public key from which to get an ASN.1 representation
CMSException
- if the key cannot be ASN.1 representedpublic java.security.PublicKey getOriginatorPublicKey(ASN1Object obj) throws CMSException
For some key agree algorithms CMS may require a special key encoding for the
OriginatorPublicKey
of a KeyAgreeRecipientInfo
. This method tries
to create a PublicKey from the given ASN1Object by using a general KeyFactory.
An application may override this method to handle keys in a provider-specific manner.
obj
- the OriginatorPublicKey as ASN1Object
CMSException
- if the ASN1Object cannot be decoded or
is invalid structuredpublic java.security.AlgorithmParameters getAlgorithmParameters(AlgorithmID algorithm) throws java.security.NoSuchAlgorithmException
algorithm
- the AlgorithmID from which to extract the parameters.
null
if no parameters are included
java.security.NoSuchAlgorithmException
- if no AlgorithmParameters for the requested algorithm
are availablepublic java.security.AlgorithmParameters getAlgorithmParameters(AlgorithmID algorithmID, java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
algorithmID
- the AlgorithmID from which to extract the parametersalgorithm
- the name of the algorithm the parameters belong to
null
if no parameters are included
java.security.NoSuchAlgorithmException
- if no AlgorithmParameters for the requested algorithm
are availablepublic java.security.AlgorithmParameters getAlgorithmParameters(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
In contrast to
algorithm
- the name of the algorithm for which AlgorithmParameters are
requested
NoSuchAlgorihmException
- if no AlgorithmParameters for the requested algorithm
are available
java.security.NoSuchAlgorithmException
public java.security.spec.AlgorithmParameterSpec getAlgorithmParameterSpec(AlgorithmID algID) throws java.security.spec.InvalidParameterSpecException
This method returns null
in any case since there is no general way
to get an AlgorithmParameterSpec from an AlgorithmID object in provider
and algorithm independent way. A SecurityProvider implementation may override this
method for some specific crypto provider.
The library uses this method to get paramaters from an RSA-PSS signature algorithm id, or from an MAC algorithm id.
algID
- the AlgorithmID from which to get the parameter specification
null
in any case since cannot be handled in provider independent way (may
be overriden by a specific provider implementation)
java.security.InvalidParameterException
- if an error occurs when trying to fetch the algorithm parameter
specification
java.security.spec.InvalidParameterSpecException
public java.security.Key getPBEKey(char[] password, AlgorithmID pbeAlg) throws java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecException
password
- the password for creating the secret keypbeAlg
- the PBE algorithm to be used
java.security.NoSuchAlgorithmException
- if the requested algorithm is not available
java.security.spec.InvalidKeySpecException
- if the key cannot be created from the password specificationpublic java.security.Key deriveKey(char[] password, AlgorithmID keyDerivationAlg, java.security.spec.AlgorithmParameterSpec paramSpec) throws java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException
password
- the password for creating the secret keykeyDerivationAlg
- the key derivation function to be usedparamSpec
- any required algorithm parameters; may be null
if no parameters are required or the parameters
are supplied via the AlgorithmID; may also
contain the password in which case the
password
parameter maybe null
java.security.NoSuchAlgorithmException
- if the requested key derivation function is not available
java.security.InvalidAlgorithmParameterException
- if the parameters are invalid or cannot be
parsed from the AlgorithmIDpublic int getKeyLength(java.security.Key key)
key
- the key for which to calculate the length
java.lang.IllegalArgumentException
- if the public key algorithm is not supportedpublic int getKeyLength(java.security.PublicKey pubKey)
pubKey
- the public key for which to calculate the length
java.lang.IllegalArgumentException
- if the public key algorithm is not supportedpublic int getKeyLength(java.security.PrivateKey privKey)
privKey
- the public key for which to calculate the length
java.lang.IllegalArgumentException
- if the private key algorithm is not supportedpublic java.security.SecureRandom getSecureRandom()
Attention This method does not synchronize on the random number generator of
this SecurityProvider. If required, an application may take care for synchronizing itself
or may ensure to set
the random number generator at
application startup. By default this method returns a new SecureRandom anytime
when called. However, when a SecureRandom has been explicitly set by calling
method setSecureRandom
, this SecureRandom is returned.
public void setSecureRandom(java.security.SecureRandom random)
Attention This method does not synchronize on the random number generator
of this SecurityProvider. If required, an application may take care for synchronizing itself
or may ensure to set the random number generator at application startup. When using
this method to set a SecureRandom object, this SecureRandom is used throughout the
whole application. If not explicitly set, method getSecureRandom
returns a new SecureRandom anytime when called.
random
- the secure random to be setpublic static int convertCipherMode(int mode)
CIPHER_ENCRYPT --> Cipher.ENCRYPT_MODE CIPHER_DECRYPT --> Cipher.DECRYPT_MODE CIPHER_WRAP --> Cipher.WRAP_MODE CIPHER_UNWRAP --> Cipher.UNWRAP_MODE
public MaskGenerationAlgorithm getMaskGenerationAlgorithm(AlgorithmID algorithm) throws java.security.NoSuchAlgorithmException
algorithm
- the AlgorithmID of the requested mask generation function
java.security.NoSuchAlgorithmException
- if no MaskGenerationAlgorithm engine is available for
the requested algorithmpublic java.security.KeyStore getKeyStore(java.lang.String keyStoreType) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException
keyStoreType
- the name of the KeyStore type
java.security.NoSuchAlgorithmException
- if no KeyStore is available for
the requested keystore type
keyStoreType
- if the KeyStore cannot be loaded
java.security.KeyStoreException
public AlgorithmID[] getMicAlgs(java.lang.String micalg)
The micalg parameter of an multipart/signed message may specify more than only one hash algorithm, separated by commas. This method steps through the algorithm names and tries to get the corresponding AlgorithmIDs.
micalg
- the micalg parameters string, e.g. "sha256"
public AlgorithmID getKeyAlgorithmID(java.security.PrivateKey privateKey) throws java.security.InvalidKeyException
privateKey
- the private key
java.security.InvalidKeyException
- if the key algorithm cannot determinedpublic java.security.spec.AlgorithmParameterSpec generateAEADParamSpec(AlgorithmID contentAuthEncAlg, byte[] encodedAuthAttributes, long inputLength) throws java.security.InvalidAlgorithmParameterException
This method is called by AuthEnvelopedDataStream
before setting up the cipher for encrypting the content.
This method only throws an InvalidAlgorithmParameterException since provider independent
creation of an AEAD AlgorithmParameterSpec is not supported. Override this
method for a specific JCA/JCE provider or use the IAIK
SecurityProvider.
contentAuthEncAlg
- the content-authenticated encryption algorithmencodedAuthAttributes
- the DER encoded authenticated attributes for building the associated data,
if not null
inputLength
- the data input length (may be required by CCM which needs to
know the length of the input data in advance; -1 otherwise)
null
if no AlgorithmParameterSpec
has been generated (e.g. because the algorithm is not supported)
java.security.InvalidAlgorithmParameterException
- if the parameters cannot be createdpublic java.security.spec.AlgorithmParameterSpec generateAEADParamSpec(AlgorithmID contentAuthEncAlg, byte[] encodedAuthAttributes, byte[] mac, long inputLength) throws java.security.InvalidAlgorithmParameterException
This method is called by AuthEnvelopedDataStream
before setting up the cipher for decrypting the content.
This method only throws an InvalidAlgorithmParameterException since provider independent
creation of an AEAD AlgorithmParameterSpec is not supported. Override this
method for a specific JCA/JCE provider or use the IAIK
SecurityProvider.
contentAuthEncAlg
- the content-authenticated encryption algorithmencodedAuthAttributes
- the encoded authenticated attributes, maybe null
if no authenticated attributes are includedmac
- the mac value; may be null
if not available at the time when setting
up the cipher and therefore may have to be set later
for the AEAD AlgorithmParameterSpec created by this methodinputLength
- the input data length; only required for CCM mode; -1 otherwise
null
if no AlgorithmParameterSpec
has been generated (e.g. because the algorithm is not supported)
java.security.InvalidAlgorithmParameterException
- if the parameters cannot be createdpublic java.security.spec.AlgorithmParameterSpec generateGCMParamSpec(AlgorithmID contentAuthEncAlg) throws java.security.InvalidAlgorithmParameterException
javax.crypto.spec.GCMParameterSpec
; only
available since Java 7) for the given content-authenticated encryption algorithm.
This method is called by EncryptedContentInfoStream
before setting up an AES GCM
cipher for encrypting the content when EnvelopedData
is used as content type. Generally CMS uses
GCM ciphers with the AuthEnvelopedData
content type. However, technically -- when appending the
mac value to the cipher text -- it is also possible to the GCM mode with the EnvelopedData
content type).
This method is called by IAIK-CMS for creating an javax.crypto.spec.GCMParameterSpec
parameter spec for use with the EnvelopedData
type. To create an AEAD parameter spec for use with the
AuthEnvelopedData
type, method
is used.
generateAEADParamSpec(AlgorithmID contentAuthEncAlg,
byte[] encodedAuthAttributes, long inputLength)
This method only throws an InvalidAlgorithmParameterException since provider independent
creation of an AEAD AlgorithmParameterSpec is not supported. Override this
method for a specific JCA/JCE provider or use the IAIK
SecurityProvider.
contentAuthEncAlg
- the content-authenticated encryption algorithm
null
if no AlgorithmParameterSpec
has been generated (e.g. because the algorithm is not supported)
java.security.InvalidAlgorithmParameterException
- if the parameters cannot be createdpublic java.security.spec.AlgorithmParameterSpec getEllipticCurveParameterSpec(java.lang.String curveName) throws java.security.spec.InvalidParameterSpecException
By default this method returns null
since it is only applicable for
ECC providers.
curveName
- the name of the curve
null
by default
java.security.spec.InvalidParameterSpecException
- if no AlgorithmParameterSpec for the given curve name is
available or cannot be createdpublic void setAEADMac(java.security.spec.AlgorithmParameterSpec paramSpec, byte[] mac) throws java.security.InvalidAlgorithmParameterException
This method is called by AuthEnvelopedDataStream
when the mac value is not available for setting up the cipher for decrypting the
content and therefore has to be "added" to the AEAD AlgorithmParameterSpec
after having read the (encrypted) content.
This method only throws an InvalidAlgorithmParameterException since provider independent
setting of the mac value for an AEAD AlgorithmParameterSpec is not supported. Override this
method for a specific JCA/JCE provider or use the IAIK
SecurityProvider.
paramSpec
- the AEAD AlgorithmParameterSpecmac
- the mac value
java.security.InvalidAlgorithmParameterException
- if the mac cannot be set
|
This Javadoc may contain text parts from text parts from IETF Internet Standard specifications (see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |