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

JCEDHPrivateKey

public class JCEDHPrivateKey extends Object implements DHPrivateKey, org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier

Fields Summary
BigInteger
x
DHParameterSpec
dhSpec
private Hashtable
pkcs12Attributes
private Vector
pkcs12Ordering
Constructors Summary
protected JCEDHPrivateKey()


     
    
    
JCEDHPrivateKey(DHPrivateKey key)

        this.x = key.getX();
        this.dhSpec = key.getParams();
    
JCEDHPrivateKey(DHPrivateKeySpec spec)

        this.x = spec.getX();
        this.dhSpec = new DHParameterSpec(spec.getP(), spec.getG());
    
JCEDHPrivateKey(org.bouncycastle.asn1.pkcs.PrivateKeyInfo info)

        DHParameter     params = new DHParameter((ASN1Sequence)info.getAlgorithmId().getParameters());
        DERInteger      derX = (DERInteger)info.getPrivateKey();

        this.x = derX.getValue();
        if (params.getL() != null)
        {
            this.dhSpec = new DHParameterSpec(params.getP(), params.getG(), params.getL().intValue());
        }
        else
        {
            this.dhSpec = new DHParameterSpec(params.getP(), params.getG());
        }
    
JCEDHPrivateKey(org.bouncycastle.crypto.params.DHPrivateKeyParameters params)

        this.x = params.getX();
        this.dhSpec = new DHParameterSpec(params.getParameters().getP(), params.getParameters().getG());
    
Methods Summary
public java.lang.StringgetAlgorithm()

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

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

        return pkcs12Ordering.elements();
    
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.

        PrivateKeyInfo          info = new PrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.dhKeyAgreement, new DHParameter(dhSpec.getP(), dhSpec.getG(), dhSpec.getL()).getDERObject()), new DERInteger(getX()));

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

return
the string "PKCS#8"

        return "PKCS#8";
    
public javax.crypto.spec.DHParameterSpecgetParams()

        return dhSpec;
    
public java.math.BigIntegergetX()

        return x;
    
private voidreadObject(java.io.ObjectInputStream in)

        x = (BigInteger)in.readObject();

        this.dhSpec = new DHParameterSpec((BigInteger)in.readObject(), (BigInteger)in.readObject(), in.readInt());
    
public voidsetBagAttribute(org.bouncycastle.asn1.DERObjectIdentifier oid, org.bouncycastle.asn1.DEREncodable attribute)

        pkcs12Attributes.put(oid, attribute);
        pkcs12Ordering.addElement(oid);
    
private voidwriteObject(java.io.ObjectOutputStream out)

        out.writeObject(this.getX());
        out.writeObject(dhSpec.getP());
        out.writeObject(dhSpec.getG());
        out.writeInt(dhSpec.getL());