public class RecipientInfo extends java.lang.Object implements ASN1Type
RecipientInfo type.
The PKCS #7: Cryptographic Message
Syntax Version 1.5 (RFC 2315) specifies the RecipientInfo
type for collecting all recipient-related information about some particular
recipient a PKCS#7 EnvelopedData or PKCS#7
SignedAndEnvelopedData object shall be sent to:
RecipientInfo ::= SEQUENCE {
version Version,
issuerAndSerialNumber IssuerAndSerialNumber,
keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
encryptedKey EncryptedKey }
EncryptedKey ::= OCTET STRING
The issuerAndSerialNumber field specifies the recipient´s
certificate by issuer distinguished name and issuer-specific serial number.
The keyEncryptionAlgorithm identifies the public-key algorithm
used for encrypting the randomly generated content-encryption key with
a recipient-specific public key. At this time only the PKCS#1
rsaEncryption method is supported. The encrypted content-encryption
key (used for encrypting the content) is stored in the encryptedKey
field.
For more information consult the PKCS #7: Cryptographic Message Syntax Version 1.5 (RFC 2315) specification.
This class provides several constructors and methods for creating a
RecipientInfo object, obtaining the component values,
and encrypting (respectively decrypting) the content-encryption key.
Assuming that cert represents the X509v3 certificate
of some intended recipient, a RecipientInfo object may be
created by supplying the certificate issuer distinguished name and the
issuer-specific serial number (through the certificate), and the recipient´s
key-encryption algorithm ID for encrypting the content-encryption key, e.g:
RecipientInfo recipient = new RecipientInfo(cert, AlgorithmID.rsaEncryption);
Note, that currently this class only supports the rsa(Encryption) key-encryption algorithm!
EnvelopedData,
EnvelopedDataStream,
SignedAndEnvelopedData,
SignedAndEnvelopedDataStream,
IssuerAndSerialNumber| Constructor and Description |
|---|
RecipientInfo()
Default Constructor.
|
RecipientInfo(ASN1Object obj)
Creates a
RecipientInfo from an ASN1Object. |
RecipientInfo(IssuerAndSerialNumber issuer,
AlgorithmID keyEA,
byte[] encryptedKey)
Creates a
RecipientInfo object with given
IssuerAndSerialNumber, key-encryption algorithm, and already
encrypted content encryption key. |
RecipientInfo(java.security.cert.X509Certificate recipientCertificate,
AlgorithmID keyEA)
Creates a RecipientInfo object from a given certificate.
|
| Modifier and Type | Method and Description |
|---|---|
void |
decode(ASN1Object obj)
Decodes the given ASN.1
RecipientInfo object for parsing
the internal structure. |
javax.crypto.SecretKey |
decryptKey(java.security.PrivateKey privateKey)
Uses a RSAPrivateKey to decrypt the encrypted content-encryption key.
|
void |
encryptKey(javax.crypto.SecretKey key)
Finishes the creation of a
RecipientInfo object by encrypting
the given secret key.. |
byte[] |
getEncryptedKey()
Returns the encrypted content-encryption key.
|
IssuerAndSerialNumber |
getIssuerAndSerialNumber()
Returns a specification of the recipient's certificate by issuer distinguished
name and issuer-specific serial number.
|
AlgorithmID |
getKeyEncryptionAlgorithm()
Returns the key-encryption algorithm used for encrypting
the content-encryption key with the recipient's public key.
|
int |
getVersion()
Returns the version of this
RecipientInfo. |
ASN1Object |
toASN1Object()
Returns this
RecipientInfo as ASN1Object. |
java.lang.String |
toString()
Returns a string giving some information about this
RecipientInfo object. |
public RecipientInfo()
RecipientInfo
object and sets the version number to 0.public RecipientInfo(IssuerAndSerialNumber issuer, AlgorithmID keyEA, byte[] encryptedKey)
RecipientInfo object with given
IssuerAndSerialNumber, key-encryption algorithm, and already
encrypted content encryption key. The already encrypted secret key
is supplied in a byte array and has been encrypted using the given
key-encryption algorithm.issuer - the IssuerAndSerialNumber specifying the
recipient´s certificate (and thereby the recipient´s
distinguished name and issuer-specific serial number)keyEncAlg - the ID of the key-encryption algorithm that has been
used for encrypting the content-encryption keyencryptedKey - the already encrypted secret keypublic RecipientInfo(java.security.cert.X509Certificate recipientCertificate,
AlgorithmID keyEA)
throws java.security.NoSuchAlgorithmException
IssuerAndSerialNumber
is obtained.
The public key from the given certificate will be used to encrypt the
symmetric content-encryption key with the given key-encryption algorithm
when calling the encryptKey method.recipientCertificate - the certificate of the recipientkeyEA - the algorithm for encrypting the symmetric keyjava.security.NoSuchAlgorithmException - if there is no implementation for the specified algorithmpublic RecipientInfo(ASN1Object obj) throws CodingException
RecipientInfo from an ASN1Object.
The ASN1Object supplied to this constructor represents an
already exisiting RecipientInfo object that may
have been created by calling toASN1Object.
obj - the RecipientInfo as ASN1ObjectCodingException - if the object can not be parsedpublic void decode(ASN1Object obj) throws CodingException
RecipientInfo object for parsing
the internal structure.
This method internally is called when creating a PKCS#7 RecipientInfo
object from an already existing RecipientInfo object,
supplied as ASN1Object.
decode in interface ASN1Typeobj - the PKCS#7 RecipientInfo as ASN1ObjectCodingException - if the object can not be parsedpublic ASN1Object toASN1Object()
RecipientInfo as ASN1Object.
Creates an ASN1 SEQUENCE object supplied with all the component values as
defined in the PKCS #7: Cryptographic
Message Syntax Version 1.5 (RFC 2315) specification. The ASN1Object returned
by this method may be used as parameter value when creating a
RecipientInfo object using the RecipientInfo(ASN1Object obj) constructor.
toASN1Object in interface ASN1TypeRecipientInfo as ASN1Object.public javax.crypto.SecretKey decryptKey(java.security.PrivateKey privateKey)
throws PKCSException,
java.security.InvalidKeyException
SecretKey.sk - the RSAPrivateKey to decrypt the encrypted content-encryption key.PKCSException - if the key-decryption process fails for some reason (e.g. the
key-encryption algorithm used by this RecipientInfo
is not implemented, or the given private key is not a RSAPrivateKey)java.security.InvalidKeyException - if the specified private key is not validpublic void encryptKey(javax.crypto.SecretKey key)
throws PKCSException
RecipientInfo object by encrypting
the given secret key..
The public key from the recipient´s certificate is used to encrypt the given content-encryption key with the rsaEncryption method. The public key must be a RSAPublicKey.
key - the symmetric key to encryptPKCSException - if the key encryption process fails for some
reason (e.g. the key-encryption algortihm used
by this RecipientInfo is not implemented,
or the recipient´s public key is not a RSAPublicKey)public int getVersion()
RecipientInfo.
This class implements version 0.public IssuerAndSerialNumber getIssuerAndSerialNumber()
IssuerAndSerialNumberpublic AlgorithmID getKeyEncryptionAlgorithm()
public byte[] getEncryptedKey()
public java.lang.String toString()
RecipientInfo object.toString in class java.lang.Object