Java Code Examples for org.bouncycastle.openpgp.PGPPublicKeyRingCollection#getPublicKeyRing()
The following examples show how to use
org.bouncycastle.openpgp.PGPPublicKeyRingCollection#getPublicKeyRing() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PGPEncryptionUtilTest.java From peer-os with Apache License 2.0 | 5 votes |
@Test public void testVerifyClearSign() throws Exception { InputStream secondPublicStream = findFile( PLUGIN_PUBLIC_KEY ); PGPPublicKeyRingCollection secondPublicKeyRingCollection = new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream( secondPublicStream ), new JcaKeyFingerprintCalculator() ); PGPPublicKeyRing pgpKeyring = secondPublicKeyRingCollection .getPublicKeyRing( secondPublicKeyRingCollection.iterator().next().getPublicKey().getKeyID() ); String signedMessage = IOUtils.toString( findFile( "signedMessage.txt" ) ); logger.info( "\n" + signedMessage ); boolean result = PGPEncryptionUtil.verifyClearSign( signedMessage.getBytes(), pgpKeyring ); if ( result ) { logger.info( "signature verified." ); } else { logger.info( "signature verification failed." ); } assertEquals( true, result ); }
Example 2
Source File: AbstractOpenPgpKeyStore.java From Smack with Apache License 2.0 | 5 votes |
@Override public PGPPublicKeyRing getPublicKeyRing(BareJid owner, OpenPgpV4Fingerprint fingerprint) throws IOException, PGPException { PGPPublicKeyRingCollection publicKeyRings = getPublicKeysOf(owner); if (publicKeyRings != null) { return publicKeyRings.getPublicKeyRing(fingerprint.getKeyId()); } return null; }
Example 3
Source File: PGPEncryptionUtilTest.java From peer-os with Apache License 2.0 | 4 votes |
@Test public void testMessageSigning() throws Exception { InputStream secondSecretStream = findFile( PLUGIN_PRIVATE_KEY ); InputStream secondPublicStream = findFile( PLUGIN_PUBLIC_KEY ); PGPSecretKeyRingCollection secretKeyRingCollection = new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( secondSecretStream ), new JcaKeyFingerprintCalculator() ); PGPSecretKeyRing secretKeyRing = secretKeyRingCollection .getSecretKeyRing( secretKeyRingCollection.iterator().next().getSecretKey().getKeyID() ); PGPSecretKey secondSecretKey = secretKeyRing.getSecretKey(); PGPPublicKeyRingCollection secondPublicKeyRingCollection = new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream( secondPublicStream ), new JcaKeyFingerprintCalculator() ); PGPPublicKeyRing pgpKeyring = secondPublicKeyRingCollection .getPublicKeyRing( secondPublicKeyRingCollection.iterator().next().getPublicKey().getKeyID() ); byte[] encryptedMessage = PGPEncryptionUtil.encrypt( "Test message.\n".getBytes(), pgpKeyring.getPublicKey(), true ); byte[] signedMessageArmor = PGPEncryptionUtil.clearSign( encryptedMessage, secondSecretKey, "123".toCharArray(), "" ); String signedMessage = new String( signedMessageArmor, StandardCharsets.UTF_8 ); logger.info( "\n" + signedMessage ); logger.info( "\n======================" ); boolean result = PGPEncryptionUtil.verifyClearSign( signedMessageArmor, pgpKeyring ); if ( result ) { logger.info( "signature verified." ); } else { logger.info( "signature verification failed." ); } byte[] extracted = PGPEncryptionUtil.extractContentFromClearSign( signedMessage.getBytes() ); byte[] decrypted = PGPEncryptionUtil.decrypt( extracted, secretKeyRing, "123" ); logger.info( "Decrypted message \n" + new String( decrypted, StandardCharsets.UTF_8 ) ); assertEquals( true, result ); }
Example 4
Source File: PGPEncryptionUtilTest.java From peer-os with Apache License 2.0 | 4 votes |
@Test public void testClearSign() throws Exception { InputStream secondSecretStream = findFile( PLUGIN_PRIVATE_KEY ); InputStream secondPublicStream = findFile( PLUGIN_PUBLIC_KEY ); PGPSecretKeyRingCollection secretKeyRingCollection = new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( secondSecretStream ), new JcaKeyFingerprintCalculator() ); PGPSecretKeyRing secretKeyRing = secretKeyRingCollection .getSecretKeyRing( secretKeyRingCollection.iterator().next().getPublicKey().getKeyID() ); PGPSecretKey secondSecretKey = secretKeyRing.getSecretKey(); PGPPublicKeyRingCollection secondPublicKeyRingCollection = new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream( secondPublicStream ), new JcaKeyFingerprintCalculator() ); PGPPublicKeyRing pgpKeyring = secondPublicKeyRingCollection .getPublicKeyRing( secondPublicKeyRingCollection.iterator().next().getPublicKey().getKeyID() ); byte[] signedMessageArmor = PGPEncryptionUtil .clearSign( IOUtils.toString( findFile( "message.txt" ) ).getBytes(), secondSecretKey, "123".toCharArray(), "" ); String signedMessage = new String( signedMessageArmor, StandardCharsets.UTF_8 ); logger.info( "\n" + signedMessage ); boolean result = PGPEncryptionUtil.verifyClearSign( signedMessage.getBytes(), pgpKeyring ); if ( result ) { logger.info( "signature verified." ); } else { logger.info( "signature verification failed." ); } assertEquals( true, result ); }
Example 5
Source File: PGPKeyId.java From pgpverify-maven-plugin with Apache License 2.0 | 4 votes |
@Override public PGPPublicKeyRing getKeyRingFromRingCollection(PGPPublicKeyRingCollection pgpRingCollection) throws PGPException { return pgpRingCollection.getPublicKeyRing(keyId); }
Example 6
Source File: PGPKeyId.java From pgpverify-maven-plugin with Apache License 2.0 | 4 votes |
@Override public PGPPublicKeyRing getKeyRingFromRingCollection(PGPPublicKeyRingCollection pgpRingCollection) throws PGPException { return pgpRingCollection.getPublicKeyRing(fingerprint); }
Example 7
Source File: TestHelper.java From peer-os with Apache License 2.0 | 3 votes |
public static PGPPublicKeyRing PGP_PUB_KEY() throws PGPException, IOException { PGPPublicKeyRingCollection pgpPublicKeyRings = new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream( new ByteArrayInputStream( PGP_PUBLIC_KEY.getBytes() ) ), new JcaKeyFingerprintCalculator() ); return pgpPublicKeyRings.getPublicKeyRing( pgpPublicKeyRings.iterator().next().getPublicKey().getKeyID() ); }