Example usage for org.bouncycastle.jce.provider JCERSAPrivateCrtKey getPrimeExponentP

List of usage examples for org.bouncycastle.jce.provider JCERSAPrivateCrtKey getPrimeExponentP

Introduction

In this page you can find the example usage for org.bouncycastle.jce.provider JCERSAPrivateCrtKey getPrimeExponentP.

Prototype

public BigInteger getPrimeExponentP() 

Source Link

Document

return the prime exponent for P.

Usage

From source file:nl.uva.vlet.grid.ssl.PrivateKeyReader.java

License:Apache License

public static byte[] getEncoded(PrivateKey inKey) {
    JCERSAPrivateCrtKey key;
    if (inKey instanceof JCERSAPrivateCrtKey)
        key = (JCERSAPrivateCrtKey) inKey;
    else/*  w  w w  .  j a v  a  2  s  .  c  om*/
        throw new IllegalArgumentException((new StringBuilder()).append("Argument was:").append(inKey)
                .append(" Expected: JCERSAPrivateCrtKey").toString());
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    DEROutputStream dOut = new DEROutputStream(bOut);
    RSAPrivateKeyStructure info = new RSAPrivateKeyStructure(key.getModulus(), key.getPublicExponent(),
            key.getPrivateExponent(), key.getPrimeP(), key.getPrimeQ(), key.getPrimeExponentP(),
            key.getPrimeExponentQ(), key.getCrtCoefficient());
    try {
        dOut.writeObject(info);
        dOut.close();
    } catch (IOException e) {
        throw new RuntimeException("Error encoding RSA public key");
    }
    return bOut.toByteArray();
}