Example usage for org.bouncycastle.asn1.pkcs RSAPrivateKey getEncoded

List of usage examples for org.bouncycastle.asn1.pkcs RSAPrivateKey getEncoded

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.pkcs RSAPrivateKey getEncoded.

Prototype

public byte[] getEncoded() throws IOException 

Source Link

Document

Return the default BER or DER encoding for this object.

Usage

From source file:org.jruby.ext.openssl.x509store.PEMInputOutput.java

License:LGPL

public static void writeRSAPrivateKey(Writer _out, RSAPrivateCrtKey obj, CipherSpec cipher, char[] passwd)
        throws IOException {
    assert (obj != null);
    BufferedWriter out = makeBuffered(_out);
    org.bouncycastle.asn1.pkcs.RSAPrivateKey keyStruct = new org.bouncycastle.asn1.pkcs.RSAPrivateKey(
            obj.getModulus(), obj.getPublicExponent(), obj.getPrivateExponent(), obj.getPrimeP(),
            obj.getPrimeQ(), obj.getPrimeExponentP(), obj.getPrimeExponentQ(), obj.getCrtCoefficient());

    if (cipher != null && passwd != null) {
        writePemEncrypted(out, PEM_STRING_RSA, keyStruct.getEncoded(), cipher, passwd);
    } else {//from  w  ww . j a va  2 s . c o m
        writePemPlain(out, PEM_STRING_RSA, keyStruct.getEncoded());
    }
}