Example usage for org.bouncycastle.asn1.x509 AlgorithmIdentifier getEncoded

List of usage examples for org.bouncycastle.asn1.x509 AlgorithmIdentifier getEncoded

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x509 AlgorithmIdentifier getEncoded.

Prototype

public byte[] getEncoded(String encoding) throws IOException 

Source Link

Document

Return either the default for "BER" or a DER encoding if "DER" is specified.

Usage

From source file:de.tsenger.sandbox.PKCS8PrivateKey.java

License:Open Source License

public static void main(String[] args) throws IOException {
    byte[] pkBytes = readBinaryFile(
            "/home/tsenger/Dokumente/Programming/animamea/certs/Key_DEATTIDBSIDE003.pkcs8");

    DERSequence pkSeq = (DERSequence) DERSequence.fromByteArray(pkBytes);

    PrivateKeyInfo pkInfo = new PrivateKeyInfo(pkSeq);

    AlgorithmIdentifier ecPublicKey = pkInfo.getPrivateKeyAlgorithm();
    System.out.println(ecPublicKey.getAlgorithm().toString());
    System.out.println(HexString.bufferToHex(ecPublicKey.getEncoded(null)));

    X9ECParameters ecp = X9ECParameters.getInstance(ecPublicKey.getParameters());

    System.out.println("N: \n" + HexString.bufferToHex(Converter.bigIntToByteArray(ecp.getN())));

    ECPrivateKey ecpk2 = ECPrivateKey.getInstance(ecPublicKey);
    //ECPrivateKey.getInstance(pkInfo.getPrivateKey());
    System.out.println("private Key: \n" + HexString.bufferToHex(Converter.bigIntToByteArray(ecpk2.getKey())));

}

From source file:eu.europa.ec.markt.dss.DSSASN1Utils.java

License:Open Source License

public static byte[] getEncoded(final AlgorithmIdentifier algorithmIdentifier) throws DSSException {

    try {//from   w  w w.  j  av a 2  s  .c o m
        return algorithmIdentifier.getEncoded(ASN1Encoding.DER);
    } catch (IOException e) {
        throw new DSSException(e);
    }
}