List of usage examples for org.bouncycastle.openpgp.operator.jcajce JcaPGPKeyConverter getPublicKey
public PublicKey getPublicKey(PGPPublicKey publicKey) throws PGPException
From source file:com.goodvikings.cryptim.api.KeyRing.java
License:BEER-WARE LICENSE
private byte[] ASN1EncodeKeys() throws IOException, PGPException { JcaPGPKeyConverter converter = new JcaPGPKeyConverter(); PrivateKey priv = converter.getPrivateKey(kp.getPrivateKey()); PublicKey pub = converter.getPublicKey(kp.getPublicKey()); ASN1EncodableVector pubSeq = new ASN1EncodableVector(); for (String jid : keys.keySet()) { pubSeq.add(new DERSequence(new ASN1Encodable[] { new DERUTF8String(jid), new DERUTF8String(nicks.get(jid)), new DERUTCTime(keys.get(jid).getCreationTime()), new DEROctetString(converter.getPublicKey(keys.get(jid)).getEncoded()) })); }//from ww w . j a v a 2 s. c om DERSequence seq = new DERSequence(new ASN1Encodable[] { new DERSequence(new ASN1Encodable[] { new DERUTCTime(kp.getPublicKey().getCreationTime()), new DEROctetString(pub.getEncoded()) }), new DEROctetString(priv.getEncoded()), new DERSequence(pubSeq) }); return seq.getEncoded(); }
From source file:com.goodvikings.cryptim.api.KeyRing.java
License:BEER-WARE LICENSE
private boolean testKeyRing() throws BadPaddingException, IllegalBlockSizeException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, NoSuchProviderException, PGPException { JcaPGPKeyConverter conv = new JcaPGPKeyConverter(); PublicKey pub = conv.getPublicKey(kp.getPublicKey()); PrivateKey priv = conv.getPrivateKey(kp.getPrivateKey()); String testData = "The quick brown fox jumps over the lazy dog."; Cipher enc = Cipher.getInstance(pub.getAlgorithm(), PROVIDER); enc.init(Cipher.ENCRYPT_MODE, pub); byte[] ciphertext = enc.doFinal(testData.getBytes()); Cipher dec = Cipher.getInstance(pub.getAlgorithm(), PROVIDER); dec.init(Cipher.DECRYPT_MODE, priv); return new String(dec.doFinal(ciphertext)).equals(testData); }