FileDocCategorySizeDatePackage
JCEECPrivateKey.javaAPI DocAzureus 3.0.3.48131Mon Mar 20 04:56:46 GMT 2006org.bouncycastle.jce.provider

JCEECPrivateKey

public class JCEECPrivateKey extends Object implements org.bouncycastle.jce.interfaces.ECPrivateKey, org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier

Fields Summary
private String
algorithm
private BigInteger
d
private org.bouncycastle.jce.spec.ECParameterSpec
ecSpec
private Hashtable
pkcs12Attributes
private Vector
pkcs12Ordering
Constructors Summary
protected JCEECPrivateKey()


     
    
    
JCEECPrivateKey(org.bouncycastle.jce.interfaces.ECPrivateKey key)

        this.d = key.getD();
        this.algorithm = key.getAlgorithm();
        this.ecSpec = key.getParams();
    
JCEECPrivateKey(String algorithm, org.bouncycastle.jce.spec.ECPrivateKeySpec spec)

        this.algorithm = algorithm;
        this.d = spec.getD();
        this.ecSpec = spec.getParams();
    
JCEECPrivateKey(String algorithm, org.bouncycastle.crypto.params.ECPrivateKeyParameters params, org.bouncycastle.jce.spec.ECParameterSpec spec)

        ECDomainParameters      dp = params.getParameters();

        this.algorithm = algorithm;
        this.d = params.getD();

        if (spec == null)
        {
            this.ecSpec = new ECParameterSpec(
                            dp.getCurve(),
                            dp.getG(),
                            dp.getN(),
                            dp.getH(),
                            dp.getSeed());
        }
        else
        {
            this.ecSpec = spec;
        }
    
JCEECPrivateKey(org.bouncycastle.asn1.pkcs.PrivateKeyInfo info)

        X962Parameters      params = new X962Parameters((DERObject)info.getAlgorithmId().getParameters());

        if (params.isNamedCurve())
        {
            DERObjectIdentifier oid = (DERObjectIdentifier)params.getParameters();
            X9ECParameters      ecP = X962NamedCurves.getByOID(oid);

            ecSpec = new ECNamedCurveParameterSpec(
                                        X962NamedCurves.getName(oid),
                                        ecP.getCurve(),
                                        ecP.getG(),
                                        ecP.getN(),
                                        ecP.getH(),
                                        ecP.getSeed());
        }
        else
        {
            X9ECParameters          ecP = new X9ECParameters((ASN1Sequence)params.getParameters());
            ecSpec = new ECParameterSpec(ecP.getCurve(),
                                            ecP.getG(),
                                            ecP.getN(),
                                            ecP.getH(),
                                            ecP.getSeed());
        }

        if (info.getPrivateKey() instanceof DERInteger)
        {
            DERInteger          derD = (DERInteger)info.getPrivateKey();

            this.d = derD.getValue();
        }
        else
        {
            ECPrivateKeyStructure   ec = new ECPrivateKeyStructure((ASN1Sequence)info.getPrivateKey());

            this.d = ec.getKey();
        }
    
Methods Summary
public java.lang.StringgetAlgorithm()

        return algorithm;
    
public org.bouncycastle.asn1.DEREncodablegetBagAttribute(org.bouncycastle.asn1.DERObjectIdentifier oid)

        return (DEREncodable)pkcs12Attributes.get(oid);
    
public java.util.EnumerationgetBagAttributeKeys()

        return pkcs12Ordering.elements();
    
public java.math.BigIntegergetD()

        return d;
    
public byte[]getEncoded()
Return a PKCS8 representation of the key. The sequence returned represents a full PrivateKeyInfo object.

return
a PKCS8 representation of the key.

        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
        DEROutputStream         dOut = new DEROutputStream(bOut);
        X962Parameters          params = null;

        if (ecSpec instanceof ECNamedCurveParameterSpec)
        {
            params = new X962Parameters(X962NamedCurves.getOID(((ECNamedCurveParameterSpec)ecSpec).getName()));
        }
        else
        {
            X9ECParameters          ecP = new X9ECParameters(
                                            ecSpec.getCurve(),
                                            ecSpec.getG(),
                                            ecSpec.getN(),
                                            ecSpec.getH(),
                                            ecSpec.getSeed());
            params = new X962Parameters(ecP);
        }

        PrivateKeyInfo          info = new PrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params.getDERObject()), new ECPrivateKeyStructure(this.getD()).getDERObject());

        try
        {
            dOut.writeObject(info);
            dOut.close();
        }
        catch (IOException e)
        {
            throw new RuntimeException("Error encoding EC private key");
        }

        return bOut.toByteArray();
    
public java.lang.StringgetFormat()
return the encoding format we produce in getEncoded().

return
the string "PKCS#8"

        return "PKCS#8";
    
public org.bouncycastle.jce.spec.ECParameterSpecgetParams()

        return ecSpec;
    
public voidsetBagAttribute(org.bouncycastle.asn1.DERObjectIdentifier oid, org.bouncycastle.asn1.DEREncodable attribute)

        pkcs12Attributes.put(oid, attribute);
        pkcs12Ordering.addElement(oid);