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

CMSEnvelopedHelper

public class CMSEnvelopedHelper extends Object

Fields Summary
static final CMSEnvelopedHelper
INSTANCE
private static final Map
KEYSIZES
private static final Map
BASE_CIPHER_NAMES
private static final Map
CIPHER_ALG_NAMES
Constructors Summary
Methods Summary
java.security.AlgorithmParameterscreateAlgorithmParameters(java.lang.String encryptionOID, java.security.Provider provider)

        try
        {
            return createAlgorithmParams(encryptionOID, provider);
        }
        catch (NoSuchAlgorithmException e)
        {
            try
            {
                String algName = (String)BASE_CIPHER_NAMES.get(encryptionOID);
                if (algName != null)
                {
                    return createAlgorithmParams(algName, provider);
                }
            }
            catch (NoSuchAlgorithmException ex)
            {
                // ignore
            }
            //
            // can't try with default provider here as parameters must be from the specified provider.
            //
            throw e;
        }
    
private java.security.AlgorithmParameterscreateAlgorithmParams(java.lang.String algName, java.security.Provider provider)

        if (provider != null)
        {
            return AlgorithmParameters.getInstance(algName, provider);
        }
        else
        {
            return AlgorithmParameters.getInstance(algName);
        }
    
javax.crypto.CiphercreateAsymmetricCipher(java.lang.String encryptionOid, java.security.Provider provider)

        try
        {
            return createCipher(encryptionOid, provider);
        }
        catch (NoSuchAlgorithmException e)
        {
            return createCipher(getAsymmetricEncryptionAlgName(encryptionOid), provider);
        }
    
private javax.crypto.CiphercreateCipher(java.lang.String algName, java.security.Provider provider)

        if (provider != null)
        {
            return Cipher.getInstance(algName, provider);
        }
        else
        {
            return Cipher.getInstance(algName);
        }
    
private javax.crypto.KeyGeneratorcreateKeyGenerator(java.lang.String algName, java.security.Provider provider)

        if (provider != null)
        {
            return KeyGenerator.getInstance(algName, provider);
        }
        else
        {
            return KeyGenerator.getInstance(algName);
        }
    
javax.crypto.KeyGeneratorcreateSymmetricKeyGenerator(java.lang.String encryptionOID, java.security.Provider provider)

        try
        {
            return createKeyGenerator(encryptionOID, provider);
        }
        catch (NoSuchAlgorithmException e)
        {
            try
            {
                String algName = (String)BASE_CIPHER_NAMES.get(encryptionOID);
                if (algName != null)
                {
                    return createKeyGenerator(algName, provider);
                }
            }
            catch (NoSuchAlgorithmException ex)
            {
                // ignore
            }
            if (provider != null)
            {
                return createSymmetricKeyGenerator(encryptionOID, null);
            }
            throw e;
        }
    
private java.lang.StringgetAsymmetricEncryptionAlgName(java.lang.String encryptionAlgOID)


    
    
        KEYSIZES.put(CMSEnvelopedGenerator.DES_EDE3_CBC,  new Integer(192));
        KEYSIZES.put(CMSEnvelopedGenerator.AES128_CBC,  new Integer(128));
        KEYSIZES.put(CMSEnvelopedGenerator.AES192_CBC,  new Integer(192));
        KEYSIZES.put(CMSEnvelopedGenerator.AES256_CBC,  new Integer(256));

        BASE_CIPHER_NAMES.put(CMSEnvelopedGenerator.DES_EDE3_CBC,  "DESEDE");
        BASE_CIPHER_NAMES.put(CMSEnvelopedGenerator.AES128_CBC,  "AES");
        BASE_CIPHER_NAMES.put(CMSEnvelopedGenerator.AES192_CBC,  "AES");
        BASE_CIPHER_NAMES.put(CMSEnvelopedGenerator.AES256_CBC,  "AES");

        CIPHER_ALG_NAMES.put(CMSEnvelopedGenerator.DES_EDE3_CBC,  "DESEDE/CBC/PKCS5Padding");
        CIPHER_ALG_NAMES.put(CMSEnvelopedGenerator.AES128_CBC,  "AES/CBC/PKCS5Padding");
        CIPHER_ALG_NAMES.put(CMSEnvelopedGenerator.AES192_CBC,  "AES/CBC/PKCS5Padding");
        CIPHER_ALG_NAMES.put(CMSEnvelopedGenerator.AES256_CBC,  "AES/CBC/PKCS5Padding");
    
        if (PKCSObjectIdentifiers.rsaEncryption.getId().equals(encryptionAlgOID))
        {
            return "RSA/ECB/PKCS1Padding";
        }
        
        return encryptionAlgOID;    
    
java.security.AlgorithmParametersgetEncryptionAlgorithmParameters(java.lang.String encOID, byte[] encParams, java.security.Provider provider)

        if (encParams == null)
        {
            return null;
        }

        try
        {
            AlgorithmParameters params = createAlgorithmParameters(encOID, provider);

            params.init(encParams, "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);
        }
    
intgetKeySize(java.lang.String oid)

        Integer keySize = (Integer)KEYSIZES.get(oid);

        if (keySize == null)
        {
            throw new IllegalArgumentException("no keysize for " + oid);
        }

        return keySize.intValue();
    
java.lang.StringgetRFC3211WrapperName(java.lang.String oid)

        String alg = (String)BASE_CIPHER_NAMES.get(oid);

        if (alg == null)
        {
            throw new IllegalArgumentException("no name for " + oid);
        }

        return alg + "RFC3211Wrap";
    
javax.crypto.CiphergetSymmetricCipher(java.lang.String encryptionOID, java.security.Provider provider)

        try
        {
            return createCipher(encryptionOID, provider);
        }
        catch (NoSuchAlgorithmException e)
        {
            String alternate = (String)CIPHER_ALG_NAMES.get(encryptionOID);

            try
            {
                return createCipher(alternate, provider);
            }
            catch (NoSuchAlgorithmException ex)
            {
                if (provider != null)
                {
                    return getSymmetricCipher(encryptionOID, null); // roll back to default
                }
                throw e;
            }
        }
    
java.lang.StringgetSymmetricCipherName(java.lang.String oid)

        String algName = (String)BASE_CIPHER_NAMES.get(oid);
        if (algName != null)
        {
            return algName;
        }
        return oid;