From 790b0cf7dedce5edba3670d1d97da3701e3fc1b8 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sun, 12 Jan 2020 18:36:03 +0100 Subject: [PATCH] Add encrypt/decrypt test using existing keys --- .../encryption_signing/EncryptDecryptTest.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java index 0d6cfa7e..afef1388 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java @@ -41,6 +41,7 @@ import org.pgpainless.algorithm.PublicKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.decryption_verification.OpenPgpMetadata; +import org.pgpainless.key.TestKeys; import org.pgpainless.key.collection.PGPKeyRing; import org.pgpainless.key.generation.KeySpec; import org.pgpainless.key.generation.type.ElGamal_GENERAL; @@ -65,10 +66,6 @@ public class EncryptDecryptTest { "Unfold the imagined happiness that both\n" + "Receive in either by this dear encounter."; - public EncryptDecryptTest() { - LOGGER.log(Level.INFO, "Plain Length: " + testMessage.getBytes(UTF8).length); - } - @Ignore @Test public void freshKeysRsaToElGamalTest() @@ -122,6 +119,14 @@ public class EncryptDecryptTest { encryptDecryptForSecretKeyRings(sender, recipient); } + @Test + public void existingRsaKeysTest() throws IOException, PGPException { + PGPKeyRing sender = new PGPKeyRing(TestKeys.getJulietPublicKeyRing(), TestKeys.getJulietSecretKeyRing()); + PGPKeyRing recipient = new PGPKeyRing(TestKeys.getRomeoPublicKeyRing(), TestKeys.getRomeoSecretKeyRing()); + + encryptDecryptForSecretKeyRings(sender, recipient); + } + private void encryptDecryptForSecretKeyRings(PGPKeyRing sender, PGPKeyRing recipient) throws PGPException, IOException { PGPSecretKeyRing recipientSec = recipient.getSecretKeys(); @@ -146,10 +151,6 @@ public class EncryptDecryptTest { encryptor.close(); byte[] encryptedSecretMessage = envelope.toByteArray(); - LOGGER.log(Level.INFO, "Sender: " + PublicKeyAlgorithm.fromId(senderPub.getPublicKey().getAlgorithm()) + - " Receiver: " + PublicKeyAlgorithm.fromId(recipientPub.getPublicKey().getAlgorithm()) + - " Encrypted Length: " + encryptedSecretMessage.length); - OpenPgpMetadata encryptionResult = encryptor.getResult(); assertFalse(encryptionResult.getSignatureKeyIDs().isEmpty());