public class RecipientInfo extends java.lang.Object implements ASN1Type
RecipientInfo type.
The PKCS#7
Cryptographic Message Standard 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 RSA PKCS#7 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.
|
javax.crypto.SecretKey |
decryptKey(java.security.PrivateKey privateKey,
java.lang.String cekAlgorithm)
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.
|
RSACipherProvider |
getRSACipherProvider()
Gets the RSA cipher provider for this ReceipientInfo.
|
int |
getVersion()
Returns the version of this
RecipientInfo. |
void |
setRSACipherProvider(RSACipherProvider provider)
Sets the RSA cipher provider for this ReceipientInfo.
|
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)keyEA - 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 existing
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 Standard 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. The algorithm name of
the secret key is set to "RAW". If you want to specify the right name you
may use method decryptKey(PrivateKey
privateKey, String cekAlgorithm).privateKey - 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 javax.crypto.SecretKey decryptKey(java.security.PrivateKey privateKey,
java.lang.String cekAlgorithm)
throws PKCSException,
java.security.InvalidKeyException
SecretKey.privateKey - the RSAPrivateKey to decrypt the encrypted content-encryption key.cekAlgorithm - the name of the content encryption algorithm (e.g. "DES") to be
set for the recovered secret content encryption key. Setting the
CEK algorithm name may be required in situations where the JCE
framework (e.g. JDK 1.4) does not allow unlimited strength
cryptography and so will deny a key with algorithm name "RAW" (set
when using decryptKey(PrivateKey),
but accept it with the right name, e.g. "DES".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 algorithm 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 void setRSACipherProvider(RSACipherProvider provider)
RSACipherProvider allows an
application to control the RSA cipher encryption/decryption (content
encryption key encryption/decryption) operations. To, for instance, use the
IAIK PKCS#11 provider for decryption (RSA cipher private key decryption)
only, but the first installed provider for encryption (RSA cipher public
encryption) you may set the PKCS#11 provider as RSA decryption provider:
IAIKPkcs11 pkcs11Provider = new IAIKPkcs11(); Security.addProvider(pkcs11Provider); ... RSACipherProvider rsaProv = new RSACipherProvider(null, pkcs11Provider.getName()); ... ReceipientInfo signerInfo = ...; ... recipientInfo.setRSACipherProvider(rsaProv, null);In overriding method
cipher
of the RSACipherProvider you even
can take more influence on the ciphering process.
If no RSACipherProvider is set for this RecipientInfo the first installed RSA capable crypto provider is used for RSA en/deciphering.
provider - the RSACipherProvider to be used for private/public key RSA cipher
operationspublic RSACipherProvider getRSACipherProvider()
RSACipherProvider allows an
application to control the RSA cipher encryption/decryption (content
encryption key encryption/decryption operations). It may be set by calling
method setRSACipherProvider.public java.lang.String toString()
RecipientInfo object.toString in class java.lang.Object