FileDocCategorySizeDatePackage
JCESecretKeyFactory.javaAPI DocAndroid 1.5 API16765Wed May 06 22:41:06 BST 2009org.bouncycastle.jce.provider

JCESecretKeyFactory

public class JCESecretKeyFactory extends SecretKeyFactorySpi implements PBE

Fields Summary
protected String
algName
protected org.bouncycastle.asn1.DERObjectIdentifier
algOid
Constructors Summary
protected JCESecretKeyFactory(String algName, org.bouncycastle.asn1.DERObjectIdentifier algOid)

        this.algName = algName;
        this.algOid = algOid;
    
Methods Summary
protected javax.crypto.SecretKeyengineGenerateSecret(java.security.spec.KeySpec keySpec)

        if (keySpec instanceof SecretKeySpec)
        {
            return (SecretKey)keySpec;
        }

        throw new InvalidKeySpecException("Invalid KeySpec");
    
protected java.security.spec.KeySpecengineGetKeySpec(javax.crypto.SecretKey key, java.lang.Class keySpec)

        if (keySpec == null)
        {
            throw new InvalidKeySpecException("keySpec parameter is null");
        }
        if (key == null)
        {
            throw new InvalidKeySpecException("key parameter is null");
        }
        
        if (SecretKeySpec.class.isAssignableFrom(keySpec))
        {
            return new SecretKeySpec(key.getEncoded(), algName);
        }

        try
        {
            Class[] parameters = { byte[].class };

            Constructor c = keySpec.getConstructor(parameters);
            Object[]    p = new Object[1];

            p[0] = key.getEncoded();

            return (KeySpec)c.newInstance(p);
        }
        catch (Exception e)
        {
            throw new InvalidKeySpecException(e.toString());
        }
    
protected javax.crypto.SecretKeyengineTranslateKey(javax.crypto.SecretKey key)

        if (key == null)
        {
            throw new InvalidKeyException("key parameter is null");
        }
        
        if (!key.getAlgorithm().equalsIgnoreCase(algName))
        {
            throw new InvalidKeyException("Key not of type " + algName + ".");
        }

        return new SecretKeySpec(key.getEncoded(), algName);