1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-18 09:34:51 +02:00

replace create{Encryptor,Decryptor} methods with encryptAndOrSign,decryptAndOrVerify

This commit is contained in:
Paul Schaub 2020-11-29 15:33:54 +01:00
parent accb18bd4e
commit cc1e4601e3
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
6 changed files with 33 additions and 12 deletions

View file

@ -76,7 +76,7 @@ Take for example a look at this delicious key:
Encrypting and signing data is pretty straight forward as well.
```java
EncryptionStream encryptor = PGPainless.createEncryptor()
EncryptionStream encryptor = PGPainless.encryptAndOrSign()
.onOutputStream(targetOuputStream)
.toRecipients(publicKeyRings)
.usingSecureAlgorithms()
@ -109,7 +109,7 @@ This object will contain information like to which keys the message is encrypted
To process incoming encrypted / signed data, just do the following:
```java
DecryptionStream decryptor = PGPainless.createDecryptor()
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
.onInputStream(sourceInputStream) // insert encrypted data here
.decryptWith(secretKeyDecryptor, secretKey)
.verifyWith(trustedKeyIds, senderKeys)

View file

@ -55,17 +55,38 @@ public class PGPainless {
/**
* Create an {@link EncryptionStream}, which can be used to encrypt and/or sign data using OpenPGP.
*
* @deprecated Use {@link #encryptAndOrSign()} instead.
* @return builder
*/
public static EncryptionBuilder createEncryptor() {
return encryptAndOrSign();
}
/**
* Create an {@link EncryptionStream}, which can be used to encrypt and/or sign data using OpenPGP.
* @return builder
*/
public static EncryptionBuilder encryptAndOrSign() {
return new EncryptionBuilder();
}
/**
* Create a {@link DecryptionStream}, which can be used to decrypt and/or verify data using OpenPGP.
*
* @deprecated Use {@link #decryptAndOrVerify()} instead.
* @return builder
*/
@Deprecated
public static DecryptionBuilder createDecryptor() {
return decryptAndOrVerify();
}
/**
* Create a {@link DecryptionStream}, which can be used to decrypt and/or verify data using OpenPGP.
* @return builder
*/
public static DecryptionBuilder createDecryptor() {
public static DecryptionBuilder decryptAndOrVerify() {
return new DecryptionBuilder();
}

View file

@ -56,7 +56,7 @@ public class DecryptAndVerifyMessageTest {
public void decryptMessageAndVerifySignatureTest() throws Exception {
String encryptedMessage = TestKeys.MSG_SIGN_CRYPT_JULIET_JULIET;
DecryptionStream decryptor = PGPainless.createDecryptor()
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
.onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes()))
.decryptWith(new UnprotectedKeysProtector(), new PGPSecretKeyRingCollection(Collections.singleton(juliet)))
.verifyWith(Collections.singleton(new PGPPublicKeyRing(Collections.singletonList(juliet.getPublicKey()))))

View file

@ -137,7 +137,7 @@ public class EncryptDecryptTest {
ByteArrayOutputStream envelope = new ByteArrayOutputStream();
EncryptionStream encryptor = PGPainless.createEncryptor()
EncryptionStream encryptor = PGPainless.encryptAndOrSign()
.onOutputStream(envelope)
.toRecipients(recipientPub)
.usingSecureAlgorithms()
@ -165,7 +165,7 @@ public class EncryptDecryptTest {
// Juliet trieth to comprehend Romeos words
ByteArrayInputStream envelopeIn = new ByteArrayInputStream(encryptedSecretMessage);
DecryptionStream decryptor = PGPainless.createDecryptor()
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
.onInputStream(envelopeIn)
.decryptWith(keyDecryptor, BCUtil.keyRingsToKeyRingCollection(recipientSec))
.verifyWith(BCUtil.keyRingsToKeyRingCollection(senderPub))
@ -193,7 +193,7 @@ public class EncryptDecryptTest {
byte[] data = testMessage.getBytes();
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
ByteArrayOutputStream dummyOut = new ByteArrayOutputStream();
EncryptionStream signer = PGPainless.createEncryptor().onOutputStream(dummyOut)
EncryptionStream signer = PGPainless.encryptAndOrSign().onOutputStream(dummyOut)
.doNotEncrypt()
.createDetachedSignature()
.signWith(keyRingProtector, signingKeys.getSecretKeys())
@ -214,7 +214,7 @@ public class EncryptDecryptTest {
// CHECKSTYLE:ON
inputStream = new ByteArrayInputStream(testMessage.getBytes());
DecryptionStream verifier = PGPainless.createDecryptor().onInputStream(inputStream)
DecryptionStream verifier = PGPainless.decryptAndOrVerify().onInputStream(inputStream)
.doNotDecrypt()
.verifyDetachedSignature(new ByteArrayInputStream(armorSig.getBytes()))
.verifyWith(Collections.singleton(signingKeys.getPublicKeys()))
@ -235,7 +235,7 @@ public class EncryptDecryptTest {
byte[] data = testMessage.getBytes();
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
ByteArrayOutputStream signOut = new ByteArrayOutputStream();
EncryptionStream signer = PGPainless.createEncryptor().onOutputStream(signOut)
EncryptionStream signer = PGPainless.encryptAndOrSign().onOutputStream(signOut)
.doNotEncrypt()
.signWith(keyRingProtector, signingKeys.getSecretKeys())
.asciiArmor();
@ -247,7 +247,7 @@ public class EncryptDecryptTest {
// CHECKSTYLE:ON
inputStream = new ByteArrayInputStream(signOut.toByteArray());
DecryptionStream verifier = PGPainless.createDecryptor().onInputStream(inputStream)
DecryptionStream verifier = PGPainless.decryptAndOrVerify().onInputStream(inputStream)
.doNotDecrypt()
.verifyWith(Collections.singleton(signingKeys.getPublicKeys()))
.ignoreMissingPublicKeys()

View file

@ -116,7 +116,7 @@ public class LengthTest {
ByteArrayOutputStream envelope = new ByteArrayOutputStream();
OutputStream encryptor = PGPainless.createEncryptor()
OutputStream encryptor = PGPainless.encryptAndOrSign()
.onOutputStream(envelope)
.toRecipients(recipientPub)
// .doNotEncrypt()

View file

@ -180,7 +180,7 @@ public class ChangeSecretKeyRingPassphraseTest {
private void signDummyMessageWithKeysAndPassphrase(PGPKeyRing keyRing, Passphrase passphrase) throws IOException, PGPException {
String dummyMessage = "dummy";
ByteArrayOutputStream dummy = new ByteArrayOutputStream();
EncryptionStream stream = PGPainless.createEncryptor().onOutputStream(dummy)
EncryptionStream stream = PGPainless.encryptAndOrSign().onOutputStream(dummy)
.doNotEncrypt()
.signWith(PasswordBasedSecretKeyRingProtector.forKey(keyRing.getSecretKeys(), passphrase), keyRing.getSecretKeys())
.noArmor();