Java Code Examples for org.bouncycastle.openpgp.PGPKeyPair#getPublicKey()
The following examples show how to use
org.bouncycastle.openpgp.PGPKeyPair#getPublicKey() .
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: GhostrydeTest.java From nomulus with Apache License 2.0 | 6 votes |
@Test @Ignore("Intentionally corrupting a PGP key is easier said than done >_>") public void testFailure_keyCorruption() throws Exception { FakeKeyringModule keyringModule = new FakeKeyringModule(); byte[] data = "Fanatics have their dreams, wherewith they weave.".getBytes(UTF_8); PGPKeyPair rsa = keyringModule.get("[email protected]", ENCRYPT); PGPPublicKey publicKey = rsa.getPublicKey(); // Make the last byte of the private key off by one. muahahaha byte[] keyData = rsa.getPrivateKey().getPrivateKeyDataPacket().getEncoded(); keyData[keyData.length - 1]++; PGPPrivateKey privateKey = new PGPPrivateKey( rsa.getKeyID(), rsa.getPrivateKey().getPublicKeyPacket(), rsa.getPrivateKey().getPrivateKeyDataPacket()); ByteArrayOutputStream bsOut = new ByteArrayOutputStream(); try (OutputStream encoder = Ghostryde.encoder(bsOut, publicKey)) { encoder.write(data); } ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray()); try (InputStream decoder = Ghostryde.decoder(bsIn, privateKey)) { ByteStreams.copy(decoder, ByteStreams.nullOutputStream()); } }
Example 2
Source File: DummyKeyringModule.java From nomulus with Apache License 2.0 | 5 votes |
/** Always returns a {@link InMemoryKeyring} instance. */ @Provides @Named("DummyKeyring") static InMemoryKeyring provideDummyKeyring() { PGPKeyPair dummyKey; try (InputStream publicInput = PGP_PUBLIC_KEYRING.openStream(); InputStream privateInput = PGP_PRIVATE_KEYRING.openStream()) { PGPPublicKeyRingCollection publicKeys = new BcPGPPublicKeyRingCollection(PGPUtil.getDecoderStream(publicInput)); PGPSecretKeyRingCollection privateKeys = new BcPGPSecretKeyRingCollection(PGPUtil.getDecoderStream(privateInput)); dummyKey = lookupKeyPair(publicKeys, privateKeys, EMAIL_ADDRESS, ENCRYPT_SIGN); } catch (PGPException | IOException e) { throw new VerifyException("Failed to load PGP keys from jar", e); } // Use the same dummy PGP keypair for all required PGP keys -- a real production system would // have different values for these keys. Pass dummy values for all Strings. return new InMemoryKeyring( dummyKey, dummyKey, dummyKey.getPublicKey(), dummyKey, dummyKey.getPublicKey(), "not a real key", "not a real key", "not a real password", "not a real API key", "not a real login", "not a real password", "not a real login", "not a real credential", "not a real password", "not a real password"); }
Example 3
Source File: GhostrydeTest.java From nomulus with Apache License 2.0 | 5 votes |
@Test public void testFailure_keyMismatch() throws Exception { FakeKeyringModule keyringModule = new FakeKeyringModule(); byte[] data = "Fanatics have their dreams, wherewith they weave.".getBytes(UTF_8); PGPKeyPair dsa1 = keyringModule.get("[email protected]", ENCRYPT); PGPKeyPair dsa2 = keyringModule.get("[email protected]", ENCRYPT); PGPPublicKey publicKey = dsa1.getPublicKey(); PGPPrivateKey privateKey = dsa2.getPrivateKey(); ByteArrayOutputStream bsOut = new ByteArrayOutputStream(); try (OutputStream encoder = Ghostryde.encoder(bsOut, publicKey)) { encoder.write(data); } ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray()); RuntimeException thrown = assertThrows( RuntimeException.class, () -> { try (InputStream decoder = Ghostryde.decoder(bsIn, privateKey)) { ByteStreams.copy(decoder, ByteStreams.nullOutputStream()); } }); assertThat(thrown).hasCauseThat().isInstanceOf(PGPException.class); assertThat(thrown) .hasCauseThat() .hasMessageThat() .contains( "Message was encrypted for keyids [a59c132f3589a1d5] but ours is c9598c84ec70b9fd"); }
Example 4
Source File: PersonalKey.java From desktopclient-java with GNU General Public License v3.0 | 5 votes |
private PersonalKey(PGPKeyPair authKP, PGPKeyPair signKP, PGPKeyPair encryptKP, X509Certificate bridgeCert, String uid) throws PGPException { mAuthKey = authKP.getPublicKey(); mLoginKey = PGPUtils.convertPrivateKey(authKP.getPrivateKey()); mSignKey = signKP; mEncryptKey = encryptKP; mBridgeCert = bridgeCert; mUID = uid; }