Example usage for org.bouncycastle.openpgp.operator.jcajce JcaPGPKeyConverter getPGPPublicKey

List of usage examples for org.bouncycastle.openpgp.operator.jcajce JcaPGPKeyConverter getPGPPublicKey

Introduction

In this page you can find the example usage for org.bouncycastle.openpgp.operator.jcajce JcaPGPKeyConverter getPGPPublicKey.

Prototype

public PGPPublicKey getPGPPublicKey(int algorithm, PublicKey pubKey, Date time) throws PGPException 

Source Link

Document

Create a PGPPublicKey from the passed in JCA one.

Usage

From source file:com.goodvikings.cryptim.api.KeyRing.java

License:BEER-WARE LICENSE

private void ASN1DecodeKeys(byte[] plain) throws IOException, PGPException, NoSuchProviderException,
        ParseException, InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException {
    JcaPGPKeyConverter converter = new JcaPGPKeyConverter();

    ASN1Sequence seq = (ASN1Sequence) new ASN1InputStream(new ByteArrayInputStream(plain)).readObject();

    PGPPublicKey pub = converter.getPGPPublicKey(PGPPublicKey.RSA_GENERAL,
            new RSAPublicKeyImpl(
                    ((ASN1OctetString) ((ASN1Sequence) seq.getObjectAt(0)).getObjectAt(1)).getOctets()),
            ((ASN1UTCTime) ((ASN1Sequence) seq.getObjectAt(0)).getObjectAt(0)).getAdjustedDate());
    kp = new PGPKeyPair(pub, converter.getPGPPrivateKey(pub, KeyFactory.getInstance("RSA")
            .generatePrivate(new PKCS8EncodedKeySpec(((ASN1OctetString) seq.getObjectAt(1)).getOctets()))));

    ASN1Sequence keySeq = (ASN1Sequence) seq.getObjectAt(2);

    for (int i = 0; i < keySeq.size(); i++) {
        keys.put(((DERUTF8String) ((ASN1Sequence) keySeq.getObjectAt(i)).getObjectAt(0)).getString(),
                converter.getPGPPublicKey(PGPPublicKey.RSA_GENERAL, new RSAPublicKeyImpl(
                        ((ASN1OctetString) ((ASN1Sequence) keySeq.getObjectAt(i)).getObjectAt(3)).getOctets()),
                        ((ASN1UTCTime) ((ASN1Sequence) keySeq.getObjectAt(i)).getObjectAt(2))
                                .getAdjustedDate()));
        nicks.put(((DERUTF8String) ((ASN1Sequence) keySeq.getObjectAt(i)).getObjectAt(0)).getString(),
                ((DERUTF8String) ((ASN1Sequence) keySeq.getObjectAt(i)).getObjectAt(1)).getString());
    }/*from  ww  w  .  j  a  v a  2s  . co  m*/
}