FileDocCategorySizeDatePackage
PrivateKeyInfo.javaAPI DocAndroid 1.5 API3806Wed May 06 22:41:06 BST 2009org.bouncycastle.asn1.pkcs

PrivateKeyInfo

public class PrivateKeyInfo extends org.bouncycastle.asn1.ASN1Encodable

Fields Summary
private org.bouncycastle.asn1.DERObject
privKey
private org.bouncycastle.asn1.x509.AlgorithmIdentifier
algId
private org.bouncycastle.asn1.ASN1Set
attributes
Constructors Summary
public PrivateKeyInfo(org.bouncycastle.asn1.x509.AlgorithmIdentifier algId, org.bouncycastle.asn1.DERObject privateKey)

        this.privKey = privateKey;
        this.algId = algId;
    
public PrivateKeyInfo(org.bouncycastle.asn1.ASN1Sequence seq)

        Enumeration e = seq.getObjects();

        BigInteger  version = ((DERInteger)e.nextElement()).getValue();
        if (version.intValue() != 0)
        {
            throw new IllegalArgumentException("wrong version for private key info");
        }

        algId = new AlgorithmIdentifier((ASN1Sequence)e.nextElement());

        try
        {
            ASN1InputStream         aIn = new ASN1InputStream(((ASN1OctetString)e.nextElement()).getOctets());

            privKey = aIn.readObject();
        }
        catch (IOException ex)
        {
            throw new IllegalArgumentException("Error recoverying private key from sequence");
        }
        
        if (e.hasMoreElements())
        {
           attributes = ASN1Set.getInstance((ASN1TaggedObject)e.nextElement(), false);
        }
    
Methods Summary
public org.bouncycastle.asn1.x509.AlgorithmIdentifiergetAlgorithmId()

        return algId;
    
public org.bouncycastle.asn1.ASN1SetgetAttributes()

        return attributes;
    
public static org.bouncycastle.asn1.pkcs.PrivateKeyInfogetInstance(org.bouncycastle.asn1.ASN1TaggedObject obj, boolean explicit)

        return getInstance(ASN1Sequence.getInstance(obj, explicit));
    
public static org.bouncycastle.asn1.pkcs.PrivateKeyInfogetInstance(java.lang.Object obj)

        if (obj instanceof PrivateKeyInfo)
        {
            return (PrivateKeyInfo)obj;
        }
        else if (obj instanceof ASN1Sequence)
        {
            return new PrivateKeyInfo((ASN1Sequence)obj);
        }

        throw new IllegalArgumentException("unknown object in factory");
    
public org.bouncycastle.asn1.DERObjectgetPrivateKey()

        return privKey;
    
public org.bouncycastle.asn1.DERObjecttoASN1Object()
write out an RSA private key with it's asscociated information as described in PKCS8.
PrivateKeyInfo ::= SEQUENCE {
version Version,
privateKeyAlgorithm AlgorithmIdentifier {{PrivateKeyAlgorithms}},
privateKey PrivateKey,
attributes [0] IMPLICIT Attributes OPTIONAL
}
Version ::= INTEGER {v1(0)} (v1,...)

PrivateKey ::= OCTET STRING

Attributes ::= SET OF Attribute

        ASN1EncodableVector v = new ASN1EncodableVector();

        v.add(new DERInteger(0));
        v.add(algId);
        v.add(new DEROctetString(privKey));

        if (attributes != null)
        {
            v.add(new DERTaggedObject(false, 0, attributes));
        }
        
        return new DERSequence(v);