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

JCEECPublicKey

public class JCEECPublicKey extends Object implements org.bouncycastle.jce.interfaces.ECPublicKey

Fields Summary
private String
algorithm
private org.bouncycastle.math.ec.ECPoint
q
private org.bouncycastle.jce.spec.ECParameterSpec
ecSpec
Constructors Summary
JCEECPublicKey(String algorithm, org.bouncycastle.jce.spec.ECPublicKeySpec spec)


    
                      
             
    
        this.algorithm = algorithm;
        this.q = spec.getQ();
        this.ecSpec = spec.getParams();
    
JCEECPublicKey(String algorithm, org.bouncycastle.crypto.params.ECPublicKeyParameters params, org.bouncycastle.jce.spec.ECParameterSpec spec)

        ECDomainParameters      dp = params.getParameters();

        this.algorithm = algorithm;
        this.q = params.getQ();

        if (spec == null)
        {
            this.ecSpec = new ECParameterSpec(
                            dp.getCurve(),
                            dp.getG(),
                            dp.getN(),
                            dp.getH(),
                            dp.getSeed());
        }
        else
        {
            this.ecSpec = spec;
        }
    
JCEECPublicKey(String algorithm, org.bouncycastle.jce.interfaces.ECPublicKey key)

        this.q = key.getQ();
        this.algorithm = key.getAlgorithm();
        this.ecSpec = key.getParams();
    
JCEECPublicKey(String algorithm, org.bouncycastle.math.ec.ECPoint q, org.bouncycastle.jce.spec.ECParameterSpec ecSpec)

        this.algorithm = algorithm;
        this.q = q;
        this.ecSpec = ecSpec;
    
JCEECPublicKey(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo 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());
        }

        DERBitString    bits = info.getPublicKeyData();
        byte[]          data = bits.getBytes();
		ASN1OctetString	key = new DEROctetString(data);

        //
        // extra octet string - one of our old certs...
        //
        if (data[0] == 0x04 && data[1] == data.length - 2 
            && (data[2] == 0x02 || data[2] == 0x03))
        {
            try
            {
                ByteArrayInputStream    bIn = new ByteArrayInputStream(data);
                DERInputStream          dIn = new DERInputStream(bIn);

                key = (ASN1OctetString)dIn.readObject();
            }
            catch (IOException ex)
            {
                throw new IllegalArgumentException("error recovering public key");
            }
        }

        X9ECPoint       derQ = new X9ECPoint(ecSpec.getCurve(), key);

        this.q = derQ.getPoint();
    
Methods Summary
public java.lang.StringgetAlgorithm()

        return algorithm;
    
public byte[]getEncoded()

        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);
        }

        ASN1OctetString    p = (ASN1OctetString)(new X9ECPoint(this.getQ()).getDERObject());

        SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params.getDERObject()), p.getOctets());

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

        return bOut.toByteArray();
    
public java.lang.StringgetFormat()

        return "X.509";
    
public org.bouncycastle.jce.spec.ECParameterSpecgetParams()

        return ecSpec;
    
public org.bouncycastle.math.ec.ECPointgetQ()

        return q;
    
public java.lang.StringtoString()

        StringBuffer    buf = new StringBuffer();
        String          nl = System.getProperty("line.separator");

        buf.append("EC Public Key" + nl);
        buf.append("            X: " + this.getQ().getX().toBigInteger().toString(16) + nl);
        buf.append("            Y: " + this.getQ().getY().toBigInteger().toString(16) + nl);

        return buf.toString();