FileDocCategorySizeDatePackage
JDKKeyFactory.javaAPI DocAzureus 3.0.3.410197Wed Mar 22 10:35:02 GMT 2006org.bouncycastle.jce.provider

JDKKeyFactory

public abstract class JDKKeyFactory extends KeyFactorySpi
author
parg

Fields Summary
Constructors Summary
Methods Summary
static java.security.PrivateKeycreatePrivateKeyFromDERStream(java.io.InputStream in)

            return createPrivateKeyFromPrivateKeyInfo(
                    new PrivateKeyInfo((ASN1Sequence)(new DERInputStream(in).readObject())));
        
static java.security.PrivateKeycreatePrivateKeyFromPrivateKeyInfo(org.bouncycastle.asn1.pkcs.PrivateKeyInfo info)
create a private key from the given public key info object.

            AlgorithmIdentifier     algId = info.getAlgorithmId();
            
            /*
            if (algId.getObjectId().equals(PKCSObjectIdentifiers.rsaEncryption))
            {
                  return new JCERSAPrivateCrtKey(info);
            }
            else if (algId.getObjectId().equals(PKCSObjectIdentifiers.dhKeyAgreement))
            {
                  return new JCEDHPrivateKey(info);
            }
            else if (algId.getObjectId().equals(OIWObjectIdentifiers.elGamalAlgorithm))
            {
                  return new JCEElGamalPrivateKey(info);
            }
            else if (algId.getObjectId().equals(X9ObjectIdentifiers.id_dsa))
            {
                  return new JDKDSAPrivateKey(info);
            }
            else */
            if (algId.getObjectId().equals(X9ObjectIdentifiers.id_ecPublicKey))
            {
                  return new JCEECPrivateKey(info);
            }
            else
            {
                throw new RuntimeException("algorithm identifier in key not recognised");
            }
        
static java.security.PublicKeycreatePublicKeyFromDERStream(java.io.InputStream in)

		        return createPublicKeyFromPublicKeyInfo(
		                new SubjectPublicKeyInfo((ASN1Sequence)(new DERInputStream(in).readObject())));
		    
static java.security.PublicKeycreatePublicKeyFromPublicKeyInfo(SubjectPublicKeyInfo info)

        AlgorithmIdentifier     algId = info.getAlgorithmId();
        
        if (algId.getObjectId().equals(PKCSObjectIdentifiers.rsaEncryption)
        	|| algId.getObjectId().equals(X509ObjectIdentifiers.id_ea_rsa))
        {
              return new JCERSAPublicKey(info);
        }
        else if (algId.getObjectId().equals(X9ObjectIdentifiers.id_ecPublicKey))
        {
              return new JCEECPublicKey(info);
        }
        else
        {
            throw new RuntimeException("algorithm identifier in key not recognised");
        }
    
protected java.security.spec.KeySpecengineGetKeySpec(java.security.Key key, java.lang.Class spec)

           if (spec.isAssignableFrom(PKCS8EncodedKeySpec.class) && key.getFormat().equals("PKCS#8"))
           {
                   return new PKCS8EncodedKeySpec(key.getEncoded());
           }
           else if (spec.isAssignableFrom(X509EncodedKeySpec.class) && key.getFormat().equals("X.509"))
           {
                   return new X509EncodedKeySpec(key.getEncoded());
           }
           else if (spec.isAssignableFrom(RSAPublicKeySpec.class) && key instanceof RSAPublicKey)
           {
                RSAPublicKey    k = (RSAPublicKey)key;

                return new RSAPublicKeySpec(k.getModulus(), k.getPublicExponent());
           }
           else if (spec.isAssignableFrom(RSAPrivateKeySpec.class) && key instanceof RSAPrivateKey)
           {
                RSAPrivateKey    k = (RSAPrivateKey)key;

                return new RSAPrivateKeySpec(k.getModulus(), k.getPrivateExponent());
           }
           else if (spec.isAssignableFrom(RSAPrivateCrtKeySpec.class) && key instanceof RSAPrivateCrtKey)
           {
                RSAPrivateCrtKey    k = (RSAPrivateCrtKey)key;

                return new RSAPrivateCrtKeySpec(
                                k.getModulus(), k.getPublicExponent(),
                                k.getPrivateExponent(),
                                k.getPrimeP(), k.getPrimeQ(),
                                k.getPrimeExponentP(), k.getPrimeExponentQ(),
                                k.getCrtCoefficient());
           }


            throw new RuntimeException("not implemented yet " + key + " " + spec);
        
protected java.security.KeyengineTranslateKey(java.security.Key key)

            if (key instanceof RSAPublicKey)
            {
                return new JCERSAPublicKey((RSAPublicKey)key);
            }
            else if (key instanceof RSAPrivateCrtKey)
            {
                //return new JCERSAPrivateCrtKey((RSAPrivateCrtKey)key);
            }
            else if (key instanceof RSAPrivateKey)
            {
                //return new JCERSAPrivateKey((RSAPrivateKey)key);
            }
            else if (key instanceof DHPublicKey)
            {
                //return new JCEDHPublicKey((DHPublicKey)key);
            }
            else if (key instanceof DHPrivateKey)
            {
                //return new JCEDHPrivateKey((DHPrivateKey)key);
            }
            else if (key instanceof DSAPublicKey)
            {
                //return new JDKDSAPublicKey((DSAPublicKey)key);
            }
            else if (key instanceof DSAPrivateKey)
            {
                //return new JDKDSAPrivateKey((DSAPrivateKey)key);
            }
            else if (key instanceof ElGamalPublicKey)
            {
                //return new JCEElGamalPublicKey((ElGamalPublicKey)key);
            }
            else if (key instanceof ElGamalPrivateKey)
            {
                //return new JCEElGamalPrivateKey((ElGamalPrivateKey)key);
            }

            throw new InvalidKeyException("key type unknown");