FileDocCategorySizeDatePackage
RecipientInformation.javaAPI DocBouncy Castle Crypto API 1.41 (Java 1.5)6926Wed Oct 01 10:55:28 BST 2008org.bouncycastle.cms

RecipientInformation

public abstract class RecipientInformation extends Object

Fields Summary
protected RecipientId
_rid
protected org.bouncycastle.asn1.x509.AlgorithmIdentifier
_encAlg
protected org.bouncycastle.asn1.x509.AlgorithmIdentifier
_keyEncAlg
protected InputStream
_data
Constructors Summary
protected RecipientInformation(org.bouncycastle.asn1.x509.AlgorithmIdentifier encAlg, org.bouncycastle.asn1.x509.AlgorithmIdentifier keyEncAlg, InputStream data)


     
         
         
                 
    
        this._encAlg = encAlg;
        this._keyEncAlg = keyEncAlg;
        this._data = data;
    
Methods Summary
private byte[]encodeObj(org.bouncycastle.asn1.DEREncodable obj)

        if (obj != null)
        {
            return obj.getDERObject().getEncoded();
        }

        return null;
    
public byte[]getContent(java.security.Key key, java.lang.String provider)

        try
        {
            if (_data instanceof ByteArrayInputStream)
            {
                _data.reset();
            }
            
            return CMSUtils.streamToByteArray(getContentStream(key, provider).getContentStream());
        }
        catch (IOException e)
        {
            throw new RuntimeException("unable to parse internal stream: " + e);
        }
    
protected CMSTypedStreamgetContentFromSessionKey(java.security.Key sKey, java.security.Provider provider)

        String              encAlg = _encAlg.getObjectId().getId();
        
        try
        {
            Cipher              cipher;

            cipher =  CMSEnvelopedHelper.INSTANCE.getSymmetricCipher(encAlg, provider);
           
            ASN1Object sParams = (ASN1Object)_encAlg.getParameters();
    
            if (sParams != null && !(sParams instanceof ASN1Null))
            {
                AlgorithmParameters params = CMSEnvelopedHelper.INSTANCE.createAlgorithmParameters(encAlg, cipher.getProvider());

                params.init(sParams.getEncoded(), "ASN.1");
    
                cipher.init(Cipher.DECRYPT_MODE, sKey, params);
            }
            else
            {
                if (encAlg.equals(CMSEnvelopedDataGenerator.DES_EDE3_CBC)
                    || encAlg.equals(CMSEnvelopedDataGenerator.IDEA_CBC)
                    || encAlg.equals(CMSEnvelopedDataGenerator.CAST5_CBC))
                {
                    cipher.init(Cipher.DECRYPT_MODE, sKey, new IvParameterSpec(new byte[8]));
                }
                else
                {
                    cipher.init(Cipher.DECRYPT_MODE, sKey);
                }
            }
    
            return new CMSTypedStream(new CipherInputStream(_data, cipher));
        }
        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);
        }
        catch (InvalidAlgorithmParameterException e)
        {
            throw new CMSException("algorithm parameters invalid.", e);
        }
        catch (IOException e)
        {
            throw new CMSException("error decoding algorithm parameters.", e);
        }
    
public abstract CMSTypedStreamgetContentStream(java.security.Key key, java.lang.String provider)

public java.lang.StringgetKeyEncryptionAlgOID()
return the object identifier for the key encryption algorithm.

return
OID for key encryption algorithm.

        return _keyEncAlg.getObjectId().getId();
    
public byte[]getKeyEncryptionAlgParams()
return the ASN.1 encoded key encryption algorithm parameters, or null if there aren't any.

return
ASN.1 encoding of key encryption algorithm parameters.

        try
        {
            return encodeObj(_keyEncAlg.getParameters());
        }
        catch (Exception e)
        {
            throw new RuntimeException("exception getting encryption parameters " + e);
        }
    
public java.security.AlgorithmParametersgetKeyEncryptionAlgorithmParameters(java.lang.String provider)
Return an AlgorithmParameters object giving the encryption parameters used to encrypt the key this recipient holds.

param
provider the provider to generate the parameters for.
return
the parameters object, null if there is not one.
throws
CMSException if the algorithm cannot be found, or the parameters can't be parsed.
throws
NoSuchProviderException if the provider cannot be found.

        return getKeyEncryptionAlgorithmParameters(CMSUtils.getProvider(provider));
    
public java.security.AlgorithmParametersgetKeyEncryptionAlgorithmParameters(java.security.Provider provider)
Return an AlgorithmParameters object giving the encryption parameters used to encrypt the key this recipient holds.

param
provider the provider to generate the parameters for.
return
the parameters object, null if there is not one.
throws
CMSException if the algorithm cannot be found, or the parameters can't be parsed.

        try
        {
            byte[]  enc = this.encodeObj(_keyEncAlg.getParameters());
            if (enc == null)
            {
                return null;
            }
            
            AlgorithmParameters params = CMSEnvelopedHelper.INSTANCE.createAlgorithmParameters(getKeyEncryptionAlgOID(), provider);
            
            params.init(enc, "ASN.1");
            
            return params;
        }
        catch (NoSuchAlgorithmException e)
        {
            throw new CMSException("can't find parameters for algorithm", e);
        }
        catch (IOException e)
        {
            throw new CMSException("can't find parse parameters", e);
        }  
    
public RecipientIdgetRID()

        return _rid;