public class KeyAgreeRecipientInfo extends RecipientInfo
KeyAgreeRecipientInfo type.
The CMS Cryptographic Message Syntax
specifies the KeyAgreeRecipientInfo type as RecipientInfo choice for collecting all recipient-related information about one
or more recipients a CMS EnvelopedData or CMS
AuthenticatedData object shall be sent to when a key agreement
algorithm is used for encrypting the secret content encryption key. A
KeyAgreeRecipientInfo may hold encrypted content encryption keys for any
number of recipients using the same key agreement method and domain
parameters for that key agreement algorithm:
KeyAgreeRecipientInfo ::= SEQUENCE {
version CMSVersion, -- always set to 3
originator [0] EXPLICIT OriginatorIdentifierOrKey,
ukm [1] EXPLICIT UserKeyingMaterial OPTIONAL,
keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
recipientEncryptedKeys RecipientEncryptedKeys }
OriginatorIdentifierOrKey ::= CHOICE {
issuerAndSerialNumber IssuerAndSerialNumber,
subjectKeyIdentifier [0] SubjectKeyIdentifier,
originatorKey [1] OriginatorPublicKey }
OriginatorPublicKey ::= SEQUENCE {
algorithm AlgorithmIdentifier,
publicKey BIT STRING }
RecipientEncryptedKeys ::= SEQUENCE OF RecipientEncryptedKey
RecipientEncryptedKey ::= SEQUENCE {
rid KeyAgreeRecipientIdentifier,
encryptedKey EncryptedKey }
KeyAgreeRecipientIdentifier ::= CHOICE {
issuerAndSerialNumber IssuerAndSerialNumber,
rKeyId [0] IMPLICIT RecipientKeyIdentifier }
RecipientKeyIdentifier ::= SEQUENCE {
subjectKeyIdentifier SubjectKeyIdentifier,
date GeneralizedTime OPTIONAL,
other OtherKeyAttribute OPTIONAL }
SubjectKeyIdentifier ::= OCTET STRING
The originator field is a CHOICE with three alternatives
specifying the sender's key agreement public key. The sender uses the
corresponding private key and the recipient's public key to generate a
pairwise key. The content-encryption key is encrypted in the pairwise
key. The issuerAndSerialNumber alternative identifies the
sender's certificate, and thereby the sender's public key, by the
issuer's distinguished name and the certificate serial number. The
subjectKeyIdentifier alternative identifies the sender's
certificate, and thereby the sender's public key, by the X.509
subjectKeyIdentifier extension value. The originatorKey
alternative includes the algorithm identifier and sender's key agreement
public key. Permitting originator anonymity since the public key is not
certified.
ukm is optional. With some key agreement algorithms, the
sender provides a User Keying Material (UKM) to ensure that a different
key is generated each time the same two parties generate a pairwise key.
keyEncryptionAlgorithm identifies the key-encryption algorithm,
and any associated parameters, used to encrypt the content-encryption key
in the key-encryption key.
recipientEncryptedKeys includes a recipient identifier and
encrypted key for one or more recipients. The KeyAgreeRecipientIdentifier
is a CHOICE with two alternatives specifying the recipient's certificate,
and thereby the recipient's public key, that was used by the sender to
generate a pairwise key-encryption key. The recipient's certificate must
contain a key agreement public key. The content-encryption key is
encrypted in the pairwise key-encryption key. The issuerAndSerialNumber
alternative identifies the recipient's certificate by the issuer's
distinguished name and the certificate serial number; the
RecipientKeyIdentifier identifies the recipient certificate and
public key by X.509 SubjectKeyIdentifier and optional date and
OtherKeyAttribute. When present, the date specifies which of the
recipient's previously distributed UKMs was used by the sender.
OtherKeyAttribute shall not be used for interoperability reasons but
may contain additional information used by the recipient to locate the
public keying material used by the sender.
When using Ephemeral Static Diffie Hellman (ESDH)
(RFC 2631) or ephemeral-static
Elliptic Curve Diffien Hellman (ECDH)
(RFC 3278), the ephemeral
originator public key MUST be specified by using the
OriginatorPublicKey option for the originator
field. For these algorithms, the following key agreement algorithm
identifiers should be used:
AlgorithmID.esdhKeyAgreement
AlgorithmID.dhSinglePass_stdDH_sha1kdf_scheme
AlgorithmID.dhSinglePass_cofactorDH_sha1kdf_scheme
Note that for patent and performance reasons this class does not perform any parameter validation that may be appropriate for protecting against some kind of attacks. An application itself may take care for validating the parameters of the other party´s key and it may use some of the utility methods of class iaik.utils.CryptoUtils for doing so.
This class provides several constructors and methods for creating a
KeyAgreeRecipientInfo object, obtaining the component values,
and encrypting (respectively decrypting) the content-encryption key.
When creating a new KeyAgreeRecipientInfo you have to decide whether to
use the originatorPublicKey option for representing the public key
of the originator or to use a
static originator certificate. If using the originatorPublicKey option
the originator key automatically will be created the first time when
adding some
particular recipient information, e.g.:
// the key encryption (key agreement) algorithm to use: AlgorithmID keyEA = AlgorithmID.esdhKeyAgreement; // the key wrap algorithm to use: AlgorithmID keyWrapAlg = AlgorithmID.cms_3DES_wrap; // the length of the key encryption key to be generated: int kekLength = 192; // create a KeyAgreeRecipientInfo using the OriginatorPublicKey option: KeyAgreeRecipientInfo keyAgreeRecipientInfo = new KeyAgreeRecipientInfo(keyEA, keyWrapAlg, kekLength); // the ephemeral originator public key is created when adding the first recipient: X509Certificate recipientCertiificate = ...; keyAgreeRecipientInfo.addRecipient(recipientCertificate, CertificateIdentifier.ISSUER_AND_SERIALNUMBER);Note that CMS per default uses Ephemeral Static Diffie Hellman as key agreement algorithm for a KeyAgreeRecipientInfo. The originator has to be represented by the OriginatorPublicKey choice using a ephemaral originator key as in the sample above. This same holds true when ephemeral-static Elliptic Curve Diffie Hellman is used as the key agreement algorithm for a KeyAgreeRecipientInfo.
The following example shows the typical usage for including a KeyAgreeRecipientInfo into a EnvelopedData object, encoding it, decoding it at the recipient´s side and decrypt the content (we use the stream-based EnvelopedData implementation for this sample):
// the key encryption (key agreement) algorithm to use:
AlgorithmID keyEA = AlgorithmID.esdhKeyAgreement;
// the key wrap algorithm to use:
AlgorithmID keyWrapAlg = AlgorithmID.cms_3DES_wrap;
// the length of the key encryption key to be generated:
int kekLength = 192;
// create a KeyAgreeRecipientInfo using the OriginatorPublicKey option:
KeyAgreeRecipientInfo recipient =
new KeyAgreeRecipientInfo(keyEA, keyWrapAlg, kekLength);
// the ephemeral originator public key is created when adding the first recipient:
X509Certificate recipientCertiificate = ...;
keyAgreeRecipientInfo.addRecipient(recipientCertificate, CertificateIdentifier.ISSUER_AND_SERIALNUMBER);
// create an EnvelopedData for the content to be encrypted:
EnvelopedDataStream envelopedData = new EnvelopedDataStream(is, AlgorithmID.des_EDE3_CBC);
// add the recipient information:
envelopedData.addRecipientInfo(recipient);
// write the EnvelopedData to a stream thereby performing the content encryption:
int blockSize = ...;
OutputStream encoded_stream = ...;
envelopedData.writeTo(encoded_stream, blockSize);
...
// on the recipient side decode the EnvelopedData:
InputStream encodedStream = ...;
EnvelopedDataStream envelopedData = new EnvelopedData(encodedStream);
// Get information about the inherent EncryptedContentInfo:
EncryptedContentInfoStream eci = (EncryptedContentInfoStream)enveloped_data.getEncryptedContentInfo();
System.out.println("Content type: "+eci.getContentType().getName());
System.out.println("Content encryption algorithm: "+eci.getContentEncryptionAlgorithm().getName());
// setup the cipher for decryption:
envelopedData.setupCipher(recipientPrivateKey, recipientCertificate);
// read the content thereby performing the content decryption:
InputStream data_is = enveloped_data.getInputStream();
byte[] buf = new byte[1024];
int r;
while ((r = data_is.read(buf)) > 0) {
// do something useful
}
KEK_RECIPIENT_INFO, KEY_AGREE_RECIPIENT_INFO, KEY_TRANSPORT_RECIPIENT_INFO, keyEncryptionAlgorithm_, OTHER_RECIPIENT_INFO, PASSWORD_RECIPIENT_INFO, securityProvider_, version_| Constructor and Description |
|---|
KeyAgreeRecipientInfo()
Default Constructor.
|
KeyAgreeRecipientInfo(AlgorithmID keyEA,
AlgorithmID keyWrapAlg,
int kekLength)
Creates a KeyAgreeRecipientInfo for the given key encryption (key agreement)
algorithm, key wrap algorithm and user keying material.
|
KeyAgreeRecipientInfo(ASN1Object obj)
Creates a
KeyAgreeRecipientInfo from an ASN1Object. |
KeyAgreeRecipientInfo(KeyIdentifier originator,
AlgorithmID keyEA,
byte[] ukm)
Creates a KeyAgreeRecipientInfo for the given Originator, key encryption
(key agreement) algorithm and user keying material.
|
KeyAgreeRecipientInfo(X509Certificate originatorCertificate,
java.security.PrivateKey originatorPrivateKey,
int originatorIdentifierType,
AlgorithmID keyEA,
AlgorithmID keyWrapAlg,
int kekLength,
byte[] ukm)
Creates a KeyAgreeRecipientInfo object from the given originator certificate.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addRecipient(CertificateIdentifier recipientIdentifier,
byte[] encryptedKey)
Adds a recipient with given recipient identifier and already encrypted key.
|
java.security.KeyPair |
addRecipient(CertificateIdentifier recipientIdentifier,
java.security.PublicKey recipientKey)
Adds a recipient with given recipient identifier and public key agreement key.
|
java.security.KeyPair |
addRecipient(X509Certificate recipientCertificate,
int recipientIdentifierType)
Adds a recipient with the given certificate.
|
int |
countRecipientEncryptedKeys()
Counts the number of RecipientEncryptedKeys included in this KeyAgreeRecipientInfo.
|
void |
decode(ASN1Object obj)
Decodes the given ASN.1
KeyAgreeRecipientInfo object for parsing
the internal structure. |
javax.crypto.SecretKey |
decryptKey(java.security.Key privateKey)
Uses the given private key for trying to decrypt the encrypted content-encryption
key.
|
javax.crypto.SecretKey |
decryptKey(java.security.Key privateKey,
KeyIdentifier recipientIdentifier,
java.lang.String keyEncryptionAlgorithm)
Uses the given private key to decrypt the encrypted content-encryption key for
the recipient with the given recipient identifier.
|
javax.crypto.SecretKey |
decryptKey(java.security.PrivateKey privateKey,
KeyIdentifier recipientIdentifier,
java.security.PublicKey originatorPublicKey)
Uses the given private key and originator public key to decrypt the encrypted
content-encryption key for the recipient with the given recipient identifier.
|
javax.crypto.SecretKey |
decryptKey(java.security.PrivateKey privateKey,
X509Certificate recipientCertificate)
Uses the given private key to decrypt the encrypted content-encryption key for
the recipient with the given recipient certificate.
|
javax.crypto.SecretKey |
decryptKey(java.security.PrivateKey privateKey,
X509Certificate recipientCertificate,
java.security.PublicKey originatorPublicKey)
Uses the given private key and originator public key to decrypt the encrypted
content-encryption key for the recipient with the given recipient certificate.
|
void |
encryptKey(javax.crypto.SecretKey cek)
Encrypts the given secret content-encryption key.
|
byte[] |
getEncryptedKey(KeyIdentifier recipientIdentifier)
Returns the encrypted content-encryption key for the recipient with
the given keyIdentfier.
|
AlgorithmID |
getKeyWrapAlgorithm()
Returns the key wrap algorithm used for encrypting the content-encryption
key with the shared key encryption key.
|
KeyIdentifier |
getOriginator()
Returns the originator information identifying the public key of the originator.
|
KeyIdentifier[] |
getRecipientIdentifiers()
Gets the key identifier belonging to the recipient of this KeyAgreeRecipientInfo.
|
byte[] |
getUKM()
Gets the user keying material, if included.
|
boolean |
isRecipientInfoFor(KeyIdentifier recipientIdentifier)
Checks if this is a RecipientInfo for the recipient identified by the
given key identifier.
|
CertificateIdentifier |
isRecipientInfoFor(X509Certificate recipientCertificate)
Checks if this is a RecipientInfo for the given recipient certificate.
|
RecipientInfo |
makeClone() |
void |
setUKM(byte[] ukm)
Sets the optional user keying material.
|
ASN1Object |
toASN1Object()
Returns this
KeyAgreeRecipientInfo as ASN1Object. |
java.lang.String |
toString()
Returns a string giving some information about this
KeyAgreeRecipientInfo object. |
decryptKey, encodeSequence, getKeyEncryptionAlgorithm, getRecipientInfoType, getVersion, isPasswordRequired, parseRecipientInfo, parseRecipientInfo, parseRecipientInfospublic KeyAgreeRecipientInfo()
KeyAgreeRecipientInfo
object and sets the version number to 3.
public KeyAgreeRecipientInfo(AlgorithmID keyEA, AlgorithmID keyWrapAlg, int kekLength)
When using this constructor for creating a KeyAgreeRecipientInfo
the OriginatorPublicKey option is used for representing the
public key in the originator field. The OriginatorPublicKey is automatically created
the first time when adding recipient information. Any further recipient information added is
required to have a public key with domain parameters matching to those of
the originator´s key.
Note that when using ephemeral-static Diffie Hellman or ephemeral-static
Elliptic Curve Diffie Hellman as the keyEncryptionAlgorithm (key agreement
algorithm) in a KeyAgreeRecipientInfo, the OriginatorPublicKey
option MUST be used for representing the ephmeral originator public key.
Any user keying material to be used may be set by calling method setUKM.
Note that this constructor internally clones the supplied key agreement and
key wrap algorithm ids.
keyEA - the key encryption (key agreement) algorithm used for creating
a shared key encryption key for encrypting the secret content
encryption key with itkeyWrapAlg - the key wrap algorithm to be used for wrapping (encrypting)
the content encryption keykekLength - the length of the key encryption key to be created for
encrypting the content encryption key with itpublic KeyAgreeRecipientInfo(X509Certificate originatorCertificate, java.security.PrivateKey originatorPrivateKey, int originatorIdentifierType, AlgorithmID keyEA, AlgorithmID keyWrapAlg, int kekLength, byte[] ukm) throws X509ExtensionException
From the given certificate a IssuerAndSerialNumber or SubjectKeyIdentifier
(depending on the requested originator identifier type) is created for pointing to the certificate and thereby public key of
the originator.
Any time when adding recipient information the public key of the recipient is
required to have domain parameters matching to those of
the originator´s key.
Note that when using ephemeral-static Diffie Hellman or ephemeral-static
Elliptic Curve Diffie Hellman as the keyEncryptionAlgorithm (key agreement
algorithm) in a KeyAgreeRecipientInfo, the OriginatorPublicKey
option MUST be used for representing the ephmeral originator public key.
Using a certificate on the originator side would mean to use a static
originator key which is not recommended by CMS. However, when using
static-static mode, the user keying material (ukm) should NOT be
null.
Note that this constructor internally clones the supplied key agreement and
key wrap algorithm ids.
originatorCertificate - the certificate of the originatororiginatorIdentifierType - the type of the originatorIdentifier,
either CertificateIdentifier.ISSUER_AND_SERIALNUMBER or CertificateIdentifier.SUBJECT_KEY_IDENTIFIERkeyEA - the key encryption (key agreement) algorithm used for creating
a shared key encryption key for encrypting the secret content
encryption key with itkeyWrapAlg - the key wrap algorithm to be used for wrapping (encrypting)
the content encryption keykekLength - the length of the key encryption key to be created for
encrypting the content encryption key with itukm - optional user keying material that may have been used to ensure
that a different key is generated each time the same two parties
generate a pairwise key; HIGHLY recommended to be supplied when
using (static) originator keys from a certificateX509ExtensionException - if a SubjectKeyIdentifier shall be used as
originatorIdentifier, but the given cert does contain the SubjectKeyIdentifier
extension or the SubjectKeyIdentifier extension cannot be parsedjava.lang.IllegalArgumentException - if the request originatorIdentifier type is
not ISSUER_AND_SERIALNUMBER or SUBJECT_KEY_IDENTIFIERpublic KeyAgreeRecipientInfo(KeyIdentifier originator, AlgorithmID keyEA, byte[] ukm)
When using this constructor for creating a KeyAgreeRecipientInfo
recipient information only can be added for an already encrypted content
encryption key by calling method addRecipient(CertificateIdentifier recipientIdentifier, byte[] encryptedKey).
Note that this constructor internally clones the supplied key agreement algorithm id.
originator - information identifying the public key of the originator, either by
IssuerAndSerialNumber,
SubjectKeyIdentifier, or
OriginatorPublicKeykeyEA - the key encryption (key agreement) algorithm used for
encrypting the secret content encryption key with a shared key
encryption keyukm - optional user keying material that may have been used to ensure
that a different key is generated each time the same two parties
generate a pairwise key; may be nulljava.lang.IllegalArgumentException - if the specified originator key identifier is
not a IssuerAndSerialNumber,
SubjectKeyIdentifier, or
OriginatorPublicKeypublic KeyAgreeRecipientInfo(ASN1Object obj) throws CodingException
KeyAgreeRecipientInfo from an ASN1Object.
The ASN1Object supplied to this constructor represents an
already exisiting KeyAgreeRecipientInfo object that may
have been created by calling toASN1Object.
obj - the KeyAgreeRecipientInfo as ASN1ObjectCodingException - if the object can not be parsedpublic void setUKM(byte[] ukm)
User keying material may be specified to ensure that a different key is generated each time the same two parties generate a pairwise key. When using ephmeral-static Diffie Hellman user keying material should be specified when using a static originator certificate (which however should not be used with CMS).
ukm - optional user keying material that may have been used to ensure
that a different key is generated each time the same two parties
generate a pairwise key; may be nullpublic KeyIdentifier getOriginator()
IssuerAndSerialNumber,
SubjectKeyIdentifier, or
OriginatorPublicKeypublic byte[] getUKM()
User keying material may be included to ensure that a different key is generated each time the same two parties generate a pairwise key. When using ephmeral-static Diffie Hellman user keying material should be specified when using a static originator certificate (which however should not be used with CMS).
This method also may be used for setting the previously distributed ukm for a KeyAgreeRecipientInfo received.
public java.security.KeyPair addRecipient(CertificateIdentifier recipientIdentifier, java.security.PublicKey recipientKey) throws java.security.InvalidKeyException
This method may be called repeatedly for adding information for each recipient
having a public key agreement key with domain parameters matching to those
of the originator´s key. When calling this method the first time (for adding
the first recipient) and the originator key yet has not been set, this method
itself creates a OriginatorPublicKey with
domain parameters matching to those of the supplied recipient key. Any further
call to this method only will be successful if the new recipient has a public
key with domain parameters matching to those of the originator´s key.
recipientIdentifier - the CertificateIdentifier identifying the
recipient´s certificate and thereby public key (by IssuerAndSerialNumber or
RecipientKeyIdentifierrecipientKey - the public key agreement key of the recipientjava.security.InvalidKeyException - if an error occurs when creating the OriginatorPublicKey
or the supplied recipient key has domain parameters not matching to
those of the already set originator keyjava.lang.IllegalArgumentException - if the given recipient identifier is not
a IssuerAndSerialNumber or
RecipientKeyIdentifierpublic java.security.KeyPair addRecipient(X509Certificate recipientCertificate, int recipientIdentifierType) throws java.security.InvalidKeyException, X509ExtensionException
This method may called repeatedly for adding information for each recipient
having a certificate with a public key agreement key with domain parameters
matching to those of the originator´s key. When calling this method the first
time (for adding the first recipient) and the originator key yet has not been
set, this method itself creates a OriginatorPublicKey with domain parameters matching to those of the supplied
recipient key. Any further call to this method only will be successful if the
new recipient has a certificate with a public key with domain parameters
matching to those of the originator´s key.
recipientCertificate - the certificate of the recipientrecipientIdentifierType - the type of the recipientIdentifier,
either CertificateIdentifier.ISSUER_AND_SERIALNUMBER or CertificateIdentifier.RECIPIENT_KEY_IDENTIFIER. If the recipient
certificate shall be identified by using the RECIPIENT_KEY_IDENTIFIER
choice, a RecipientKeyIdentifier
without date and otherKeyAttribute is createdjava.security.InvalidKeyException - if an error occurs when creating the OriginatorPublicKey
or the public key of the recipient certificate has domain parameters
not matching to those of the already set originator keyX509ExtensionException - if the recipient certificate shall be represented by a
RecipientKeyIdentifier, but does not contain the SubjectKeyIdentifier extensionjava.lang.IllegalArgumentException - if the given recipient identifier type is not
a ISSUER_AND_SERIALNUMBER or RECIPIENT_KEY_IDENTIFIERpublic void addRecipient(CertificateIdentifier recipientIdentifier, byte[] encryptedKey) throws CMSException
Attention: This method cannot not check if the key agreement method or domain parameters of the recipient key are suitable for this KeyAgreeRecipientInfo.
recipientIdentifier - the CertificateIdentifier identifying the
recipient´s certificate and thereby public key (by IssuerAndSerialNumber or
RecipientKeyIdentifierencryptedKey - the already encrypted content encryption keyCMSException - if no originator has been set when creating this
KeyAgreeRecipientInfojava.lang.IllegalArgumentException - if the given recipient identifier is not
a IssuerAndSerialNumber or
RecipientKeyIdentifierCMSExceptionpublic void decode(ASN1Object obj) throws CodingException
KeyAgreeRecipientInfo object for parsing
the internal structure.
This method internally is called when creating a CMS KeyAgreeRecipientInfo
object from an already existing KeyAgreeRecipientInfo object,
supplied as ASN1Object.
obj - the CMS KeyAgreeRecipientInfo as ASN1ObjectCodingException - if the object can not be parsedpublic ASN1Object toASN1Object() throws CodingException
KeyAgreeRecipientInfo as ASN1Object.
The ASN1Object returned by this method represents the ASN.1 structure of a KeyAgreeRecipientInfo:
KeyAgreeRecipientInfo ::= SEQUENCE {
version CMSVersion, -- always set to 3
originator [0] EXPLICIT OriginatorIdentifierOrKey,
ukm [1] EXPLICIT UserKeyingMaterial OPTIONAL,
keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
recipientEncryptedKeys RecipientEncryptedKeys }
OriginatorIdentifierOrKey ::= CHOICE {
issuerAndSerialNumber IssuerAndSerialNumber,
subjectKeyIdentifier [0] SubjectKeyIdentifier,
originatorKey [1] OriginatorPublicKey }
OriginatorPublicKey ::= SEQUENCE {
algorithm AlgorithmIdentifier,
publicKey BIT STRING }
RecipientEncryptedKeys ::= SEQUENCE OF RecipientEncryptedKey
RecipientEncryptedKey ::= SEQUENCE {
rid KeyAgreeRecipientIdentifier,
encryptedKey EncryptedKey }
KeyAgreeRecipientIdentifier ::= CHOICE {
issuerAndSerialNumber IssuerAndSerialNumber,
rKeyId [0] IMPLICIT RecipientKeyIdentifier }
RecipientKeyIdentifier ::= SEQUENCE {
subjectKeyIdentifier SubjectKeyIdentifier,
date GeneralizedTime OPTIONAL,
other OtherKeyAttribute OPTIONAL }
SubjectKeyIdentifier ::= OCTET STRING
KeyAgreeRecipientInfo as ASN1Object.CodingException - if an de/encoding error occurspublic javax.crypto.SecretKey decryptKey(java.security.Key privateKey)
throws CMSException,
java.security.InvalidKeyException
SecretKey.
Since an KeyAgreeRecipientInfo may contain encrypted content encryption keys for more than only one recipient, but no recipient identifier can be supplied when calling this method, any included encrypted content encryption key is tried to be decrypted with the given private key, which may give some processing overhead and might bring no result if the right recipient encrypted key is not included.
Note that the originator public key is required to create the shared secret
key encryption key for subsequently decrypting the encrypted content encryption
key with it. For that reason you only can use this method if the originator
field of this KeyAgreeRecipientInfo holds the OriginatorPublicKey choice
(RFC 2630 per default uses Epemeral Static Diffie Hellman (ESDH) for
KeyAgreeRecipientInfos representing the ephemeral public key of the originator
with the OriginatorPublicKey choice).
Otherwise you have to supply the originator public key yourself for decrypting the encrypted
content encryption key.
decryptKey in class RecipientInfoprivateKey - the private key of the recipient to be used for decrypting
the encrypted content-encryption key.CMSException - if the key-decryption process fails for some reason (e.g. the
key-encryption or key-wrap algorithm used by this KeyAgreeRecipientInfo
is not implemented, a padding error occurs,...)java.security.InvalidKeyException - if the specified private key is not validpublic javax.crypto.SecretKey decryptKey(java.security.Key privateKey,
KeyIdentifier recipientIdentifier,
java.lang.String keyEncryptionAlgorithm)
throws CMSException,
java.security.InvalidKeyException
SecretKey.
Since an KeyAgreeRecipientInfo may contain encrypted content encryption keys for more than only one recipient, this method first looks if any of the included recipient encrypted keys belongs to the recipient identified by the given recipient identifier. If a recipient encrypted key is included for the recipient in mind it is decrypted with the given private key of this recipient. If no recipient identifier is supplied when calling this method, any included encrypted content encryption key is tried to be decrypted with the given private key, which may give some processing overhead and might bring no result if the right recipient encrypted key is not included.
Note that the originator public key is required to create the shared secret
key encryption key for subsequently decrypting the encrypted content encryption
key with it. For that reason you only can use this method if the originator
field of this KeyAgreeRecipientInfo holds the OriginatorPublicKey choice
(RFC 2630 per default uses Epemeral Static Diffie Hellman (ESDH) for
KeyAgreeRecipientInfos representing the ephemeral public key of the originator
with the OriginatorPublicKey choice).
Otherwise you have to supply the originator public key yourself for decrypting the encrypted
content encryption key.
decryptKey in class RecipientInfoprivateKey - the private key of the recipient to be used for decrypting
the encrypted content-encryption key.recipientIdentifier - an IssuerAndSerialNumber or RecipientKeyIdentifier
identifying the recipient of this KeyAgreeRecipientInfokeyEncryptionAlgorithm - not UsedCMSException - if the key-decryption process fails for some reason (e.g. the
key-encryption or key-wrap algorithm used by this KeyAgreeRecipientInfo
is not implemented, a padding error occurs,...)java.security.InvalidKeyException - if the specified private key is not validpublic javax.crypto.SecretKey decryptKey(java.security.PrivateKey privateKey,
KeyIdentifier recipientIdentifier,
java.security.PublicKey originatorPublicKey)
throws CMSException,
java.security.InvalidKeyException
SecretKey.
Since an KeyAgreeRecipientInfo may contain encrypted content encryption keys for more than only one recipient, this method first looks if any of the included recipient encrypted keys belongs to the recipient identified by the given recipient identifier. If a recipient encrypted key is included for the recipient in mind it is decrypted with the given private key of this recipient. If no recipient identifier is supplied when calling this method, any included encrypted content encryption key is tried to be decrypted with the given private key, which may give some processing overhead and might bring no result if the right recipient encrypted key is not included.
privateKey - the private key of the recipient to be used for decrypting
the encrypted content-encryption key.recipientIdentifier - an IssuerAndSerialNumber or RecipientKeyIdentifier
identifying the recipient of this KeyAgreeRecipientInfooriginatorPublicKey - the public key of the originator; required for
calculating the shared key encryption algorithm
used for en/decrypting the content encryption keyCMSException - if the key-decryption process fails for some reason (e.g. the
key-encryption or key-wrap algorithm used by this KeyAgreeRecipientInfo
is not implemented, a padding error occurs,...)java.security.InvalidKeyException - if the specified private key is not validpublic javax.crypto.SecretKey decryptKey(java.security.PrivateKey privateKey,
X509Certificate recipientCertificate)
throws CMSException,
java.security.InvalidKeyException
SecretKey.
Since an KeyAgreeRecipientInfo may contain encrypted content encryption keys for more than only one recipient, this method first looks if any of the included recipient encrypted keys belongs to the recipient with the given certfiicate. If a recipient encrypted key is included for the recipient in mind it is decrypted with the given private key of this recipient.
Note that the originator public key is required to create the shared secret
key encryption key for subsequently decrypting the encrypted content encryption
key with it. For that reason you only can use this method if the originator
field of this KeyAgreeRecipientInfo holds the OriginatorPublicKey choice
(RFC 2630 per default uses Epemeral Static Diffie Hellman (ESDH) for
KeyAgreeRecipientInfos representing the ephemeral public key of the originator
with the OriginatorPublicKey choice).
Otherwise you have to supply the originator public key yourself for decrypting the encrypted
content encryption key.
privateKey - the private key of the recipient to be used for decrypting
the encrypted content-encryption key.recipientCertficate - the certifcate of the recipientCMSException - if the key-decryption process fails for some reason (e.g. the
key-encryption or key-wrap algorithm used by this KeyAgreeRecipientInfo
is not implemented, a padding error occurs,...)java.security.InvalidKeyException - if the specified private key is not validpublic javax.crypto.SecretKey decryptKey(java.security.PrivateKey privateKey,
X509Certificate recipientCertificate,
java.security.PublicKey originatorPublicKey)
throws CMSException,
java.security.InvalidKeyException
SecretKey.
Since an KeyAgreeRecipientInfo may contain encrypted content encryption keys for more than only one recipient, this method first looks if any of the included recipient encrypted keys belongs to the recipient with the given recipient certificate. If a recipient encrypted key is included for the recipient in mind it is decrypted with the given private key of this recipient.
privateKey - the private key of the recipient to be used for decrypting
the encrypted content-encryption key.recipientCertficate - the certficate of the recipientoriginatorPublicKey - the public key of the originator; required for
calculating the shared key encryption algorithm
used for en/decrypting the content encryption keyCMSException - if the key-decryption process fails for some reason (e.g. the
key-encryption or key-wrap algorithm used by this KeyAgreeRecipientInfo
is not implemented, a padding error occurs,...)java.security.InvalidKeyException - if the specified private key is not validpublic void encryptKey(javax.crypto.SecretKey cek)
throws CMSException
All information (key encryption (key agreement) algorithm, key wrap algorithm, kek length, ukm, originator key, public key of the recipient) has been supplied when creating this KeyAgreeRecipientInfo respectively adding information about some recipient. This method encrypts the supplied content encryption key for any recipient that has been added to this KeyAgreeRecipientInfo.
encryptKey in class RecipientInfocek - the symmetric content-encryption key to encryptCMSException - if the key encryption process fails for some
reason (e.g. the key-encryption or key-wrap algortihm used
by this KeyAgreeRecipientInfo is not implemented,
the public key of the recipient is invalid, a padding
error occurs,...)public KeyIdentifier[] getRecipientIdentifiers()
This method implements the same named method of the abstract parent RecipientInfo class for returning the identifiers of the recipient certificates (and
thereby public keys) by issuer distinguished name and issuer-specific serial number, or
RecipientKeyIdentifier.
getRecipientIdentifiers in class RecipientInfoKeyIdentifier array holding the identifiers of the recipient certificates
(and thereby public keys) by IssuerAndSerialNumber
or RecipientKeyIdentifierpublic int countRecipientEncryptedKeys()
public boolean isRecipientInfoFor(KeyIdentifier recipientIdentifier)
isRecipientInfoFor in class RecipientInforecipientIdentifier - the key identifier belonging to the recipient
we are searching fortrue if this RecipientInfo belongs to the particular
recipient in mind, false if notpublic CertificateIdentifier isRecipientInfoFor(X509Certificate recipientCertificate)
This method steps through the RecipientEncryptedKeys included in this
KeyAgreeRecipientInfo. As long as no match is found, from the given
certificate a recipient identifier is created to be compared to the
same-type recipient identifier of the current RecipientEncryptedKey.
If a match is found the corresponding recipient identifier is returned. If
no match is found, null is returned indicating that this
KeyAgreeRecipientInfo does not belong to the recipient in mind.
Note that in the case of recipient identifier type RecipientKeyIdentifier no date or
OtherKeyAttribute can be created by this method. If date and/or
OtherKeyAttribute are used by any of the recipient key identifiers of
this KeyAgreeRecipientIdentifier you may create the search identifier
by yourself and call method isRecipientInfoFor to ask if this KeyAgreeRecipientInfo belongs to
the particular recipient in mind.
isRecipientInfoFor in class RecipientInforecipientCertificate - the certificate of the recipientnull
if notpublic byte[] getEncryptedKey(KeyIdentifier recipientIdentifier) throws CMSException
This method implements the same named method of the abstract parent
RecipientInfo class for asking if this
KeyAgreeRecipientInfo holds an encrypted key for the recipient identified
by the given key identifier (IssuerAndSerialNumber or SubjectKeyIdentifier).
Since a KeyAgreeRecipientInfo only represents one single recipient
the supplied recipientIdentifier may be null.
getEncryptedKey in class RecipientInforecipientIdentifier - information to be used for getting the right encrypted content
encryption key for the right recipient; may be not required for a
KeyAgreeRecipientInfo, but for KeyAgreeRecipientInfo) which may hold encrypted content encryption
keys for more than one recipient; may be null for only
getting the encrypted content-encryption key includedCMSException - if this KeyAgreeRecipientInfo does not belong to the recipient with
the given key identifier is includedpublic AlgorithmID getKeyWrapAlgorithm()
null if not setpublic java.lang.String toString()
KeyAgreeRecipientInfo object.toString in class java.lang.Objectpublic RecipientInfo makeClone()
makeClone in class RecipientInfo