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

RSAPrivateKeyStructure

public class RSAPrivateKeyStructure extends org.bouncycastle.asn1.ASN1Encodable

Fields Summary
private int
version
private BigInteger
modulus
private BigInteger
publicExponent
private BigInteger
privateExponent
private BigInteger
prime1
private BigInteger
prime2
private BigInteger
exponent1
private BigInteger
exponent2
private BigInteger
coefficient
private org.bouncycastle.asn1.ASN1Sequence
otherPrimeInfos
Constructors Summary
public RSAPrivateKeyStructure(BigInteger modulus, BigInteger publicExponent, BigInteger privateExponent, BigInteger prime1, BigInteger prime2, BigInteger exponent1, BigInteger exponent2, BigInteger coefficient)

        this.version = 0;
        this.modulus = modulus;
        this.publicExponent = publicExponent;
        this.privateExponent = privateExponent;
        this.prime1 = prime1;
        this.prime2 = prime2;
        this.exponent1 = exponent1;
        this.exponent2 = exponent2;
        this.coefficient = coefficient;
    
public RSAPrivateKeyStructure(org.bouncycastle.asn1.ASN1Sequence seq)

        Enumeration e = seq.getObjects();

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

        version = v.intValue();
        modulus = ((DERInteger)e.nextElement()).getValue();
        publicExponent = ((DERInteger)e.nextElement()).getValue();
        privateExponent = ((DERInteger)e.nextElement()).getValue();
        prime1 = ((DERInteger)e.nextElement()).getValue();
        prime2 = ((DERInteger)e.nextElement()).getValue();
        exponent1 = ((DERInteger)e.nextElement()).getValue();
        exponent2 = ((DERInteger)e.nextElement()).getValue();
        coefficient = ((DERInteger)e.nextElement()).getValue();
        
        if (e.hasMoreElements())
        {
            otherPrimeInfos = (ASN1Sequence)e.nextElement();
        }
    
Methods Summary
public java.math.BigIntegergetCoefficient()

        return coefficient;
    
public java.math.BigIntegergetExponent1()

        return exponent1;
    
public java.math.BigIntegergetExponent2()

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


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

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

        throw new IllegalArgumentException("unknown object in factory");
    
public java.math.BigIntegergetModulus()

        return modulus;
    
public java.math.BigIntegergetPrime1()

        return prime1;
    
public java.math.BigIntegergetPrime2()

        return prime2;
    
public java.math.BigIntegergetPrivateExponent()

        return privateExponent;
    
public java.math.BigIntegergetPublicExponent()

        return publicExponent;
    
public intgetVersion()

        return version;
    
public org.bouncycastle.asn1.DERObjecttoASN1Object()
This outputs the key in PKCS1v2 format.
RSAPrivateKey ::= SEQUENCE {
version Version,
modulus INTEGER, -- n
publicExponent INTEGER, -- e
privateExponent INTEGER, -- d
prime1 INTEGER, -- p
prime2 INTEGER, -- q
exponent1 INTEGER, -- d mod (p-1)
exponent2 INTEGER, -- d mod (q-1)
coefficient INTEGER, -- (inverse of q) mod p
otherPrimeInfos OtherPrimeInfos OPTIONAL
}

Version ::= INTEGER { two-prime(0), multi(1) }
(CONSTRAINED BY {-- version must be multi if otherPrimeInfos present --})

This routine is written to output PKCS1 version 2.1, private keys.

        ASN1EncodableVector  v = new ASN1EncodableVector();

        v.add(new DERInteger(version));                       // version
        v.add(new DERInteger(getModulus()));
        v.add(new DERInteger(getPublicExponent()));
        v.add(new DERInteger(getPrivateExponent()));
        v.add(new DERInteger(getPrime1()));
        v.add(new DERInteger(getPrime2()));
        v.add(new DERInteger(getExponent1()));
        v.add(new DERInteger(getExponent2()));
        v.add(new DERInteger(getCoefficient()));

        if (otherPrimeInfos != null)
        {
            v.add(otherPrimeInfos);
        }
        
        return new DERSequence(v);