mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-29 15:52:08 +01:00
Improve logging of tests
This commit is contained in:
parent
1828ea21e5
commit
ba6e850f6f
3 changed files with 24 additions and 24 deletions
|
@ -32,7 +32,6 @@ import org.bouncycastle.openpgp.PGPException;
|
|||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.algorithm.KeyFlag;
|
||||
|
@ -64,7 +63,6 @@ public class EncryptDecryptTest {
|
|||
"Unfold the imagined happiness that both\n" +
|
||||
"Receive in either by this dear encounter.";
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void freshKeysRsaToElGamalTest()
|
||||
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
|
||||
|
@ -77,17 +75,15 @@ public class EncryptDecryptTest {
|
|||
encryptDecryptForSecretKeyRings(sender, recipient);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void freshKeysRsaToRsaTest()
|
||||
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
|
||||
PGPKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._4096);
|
||||
PGPKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._4096);
|
||||
PGPKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072);
|
||||
PGPKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072);
|
||||
|
||||
encryptDecryptForSecretKeyRings(sender, recipient);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void freshKeysEcToEcTest()
|
||||
throws IOException, PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
|
||||
|
@ -97,21 +93,19 @@ public class EncryptDecryptTest {
|
|||
encryptDecryptForSecretKeyRings(sender, recipient);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void freshKeysEcToRsaTest()
|
||||
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
|
||||
PGPKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit");
|
||||
PGPKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._4096);
|
||||
PGPKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072);
|
||||
|
||||
encryptDecryptForSecretKeyRings(sender, recipient);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void freshKeysRsaToEcTest()
|
||||
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
|
||||
PGPKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._4096);
|
||||
PGPKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072);
|
||||
PGPKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit");
|
||||
|
||||
encryptDecryptForSecretKeyRings(sender, recipient);
|
||||
|
|
|
@ -19,6 +19,8 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
|
@ -29,30 +31,32 @@ import org.pgpainless.key.collection.PGPKeyRing;
|
|||
|
||||
public class GenerateKeyTest {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(GenerateKeyTest.class.getName());
|
||||
|
||||
@Test
|
||||
public void generateKey() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
|
||||
PGPKeyRing keyRing = PGPainless.generateKeyRing().simpleEcKeyRing("cryptie@encrypted.key", "password123");
|
||||
|
||||
print(keyRing.getPublicKeys().getPublicKey().getUserIDs().next());
|
||||
print(new OpenPgpV4Fingerprint(keyRing.getPublicKeys()));
|
||||
print(keyRing.getPublicKeys().getPublicKey().getKeyID());
|
||||
PGPKeyRing keyRing = PGPainless.generateKeyRing().simpleEcKeyRing("fresh@encrypted.key", "password123");
|
||||
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
ArmoredOutputStream armor = new ArmoredOutputStream(bytes);
|
||||
keyRing.getPublicKeys().encode(armor);
|
||||
armor.close();
|
||||
print(new String(bytes.toByteArray()));
|
||||
String publicKey = new String(bytes.toByteArray());
|
||||
|
||||
bytes = new ByteArrayOutputStream();
|
||||
armor = new ArmoredOutputStream(bytes);
|
||||
keyRing.getSecretKeys().encode(armor);
|
||||
armor.close();
|
||||
print(new String(bytes.toByteArray()));
|
||||
}
|
||||
String privateKey = new String(bytes.toByteArray());
|
||||
|
||||
public void print(Object obj) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println(obj);
|
||||
// CHECKSTYLE:ON
|
||||
LOGGER.log(Level.INFO, String.format("Generated random fresh EC key ring.\n" +
|
||||
"User-ID: %s\n" +
|
||||
"Fingerprint: %s\n" +
|
||||
"Key-ID: %s\n" +
|
||||
"%s\n" +
|
||||
"%s\n", keyRing.getPublicKeys().getPublicKey().getUserIDs().next(),
|
||||
new OpenPgpV4Fingerprint(keyRing.getPublicKeys()),
|
||||
keyRing.getPublicKeys().getPublicKey().getKeyID(),
|
||||
publicKey, privateKey));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,8 @@ public class SymmetricEncryptionTest {
|
|||
@Test
|
||||
public void testSymmetricEncryptionDecryption() throws IOException, PGPException {
|
||||
byte[] plain = message.getBytes();
|
||||
Passphrase passphrase = new Passphrase("choose_a_better_password_please".toCharArray());
|
||||
String password = "choose_a_better_password_please";
|
||||
Passphrase passphrase = new Passphrase(password.toCharArray());
|
||||
byte[] enc = PGPainless.encryptWithPassword(plain, passphrase, SymmetricKeyAlgorithm.AES_128);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ArmoredOutputStream armor = new ArmoredOutputStream(out);
|
||||
|
@ -56,7 +57,8 @@ public class SymmetricEncryptionTest {
|
|||
armor.close();
|
||||
|
||||
// Print cipher text for validation with GnuPG.
|
||||
LOGGER.log(Level.INFO, new String(out.toByteArray()));
|
||||
LOGGER.log(Level.INFO, String.format("Use ciphertext below for manual validation with GnuPG " +
|
||||
"(passphrase = '%s').\n\n%s", password, new String(out.toByteArray())));
|
||||
|
||||
byte[] plain2 = PGPainless.decryptWithPassword(enc, passphrase);
|
||||
assertArrayEquals(plain, plain2);
|
||||
|
|
Loading…
Reference in a new issue