Java 类org.bouncycastle.asn1.sec.ECPrivateKey 实例源码

项目:animamea    文件:CertificateProvider.java   
public ECPrivateKey getPrivateKey() throws IOException {
    ASN1Sequence pkSeq = null;
    pkSeq = (ASN1Sequence) ASN1Sequence.fromByteArray(pkBytes);

    PrivateKeyInfo pkInfo = PrivateKeyInfo.getInstance(pkSeq);
    ECPrivateKey ecpk = ECPrivateKey.getInstance(pkInfo.parsePrivateKey());
    return ecpk;
}
项目:animamea    文件:PKCS8PrivateKey.java   
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())));

}