FileDocCategorySizeDatePackage
KEKRecipientInformation.javaAPI DocBouncy Castle Crypto API 1.41 (Java 1.5)2733Wed Oct 01 10:55:30 BST 2008org.bouncycastle.cms

KEKRecipientInformation

public class KEKRecipientInformation extends RecipientInformation
the RecipientInfo class for a recipient who has been sent a message encrypted using a secret key known to the other side.

Fields Summary
private org.bouncycastle.asn1.cms.KEKRecipientInfo
_info
private org.bouncycastle.asn1.x509.AlgorithmIdentifier
_encAlg
Constructors Summary
public KEKRecipientInformation(org.bouncycastle.asn1.cms.KEKRecipientInfo info, org.bouncycastle.asn1.x509.AlgorithmIdentifier encAlg, InputStream data)

        super(encAlg, AlgorithmIdentifier.getInstance(info.getKeyEncryptionAlgorithm()), data);
        
        this._info = info;
        this._encAlg = encAlg;
        this._rid = new RecipientId();
        
        KEKIdentifier       kekId = info.getKekid();

        _rid.setKeyIdentifier(kekId.getKeyIdentifier().getOctets());
    
Methods Summary
public CMSTypedStreamgetContentStream(java.security.Key key, java.lang.String prov)
decrypt the content and return an input stream.

        return getContentStream(key, CMSUtils.getProvider(prov));
    
public CMSTypedStreamgetContentStream(java.security.Key key, java.security.Provider prov)
decrypt the content and return an input stream.

        try
        {
            byte[]              encryptedKey = _info.getEncryptedKey().getOctets();
            Cipher              keyCipher = Cipher.getInstance(_keyEncAlg.getObjectId().getId(), prov);

            keyCipher.init(Cipher.UNWRAP_MODE, key);

            AlgorithmIdentifier aid = _encAlg;
            String              alg = aid.getObjectId().getId();
            Key                 sKey = keyCipher.unwrap(
                                        encryptedKey, alg, Cipher.SECRET_KEY);

            return getContentFromSessionKey(sKey, prov);
        }
        catch (NoSuchAlgorithmException e)
        {
            throw new CMSException("can't find algorithm.", e);
        }
        catch (InvalidKeyException e)
        {
            throw new CMSException("key invalid in message.", e);
        }
        catch (NoSuchPaddingException e)
        {
            throw new CMSException("required padding not supported.", e);
        }