mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-30 00:02:06 +01:00
replace create{Encryptor,Decryptor} methods with encryptAndOrSign,decryptAndOrVerify
This commit is contained in:
parent
accb18bd4e
commit
cc1e4601e3
6 changed files with 33 additions and 12 deletions
|
@ -76,7 +76,7 @@ Take for example a look at this delicious key:
|
||||||
|
|
||||||
Encrypting and signing data is pretty straight forward as well.
|
Encrypting and signing data is pretty straight forward as well.
|
||||||
```java
|
```java
|
||||||
EncryptionStream encryptor = PGPainless.createEncryptor()
|
EncryptionStream encryptor = PGPainless.encryptAndOrSign()
|
||||||
.onOutputStream(targetOuputStream)
|
.onOutputStream(targetOuputStream)
|
||||||
.toRecipients(publicKeyRings)
|
.toRecipients(publicKeyRings)
|
||||||
.usingSecureAlgorithms()
|
.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:
|
To process incoming encrypted / signed data, just do the following:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
DecryptionStream decryptor = PGPainless.createDecryptor()
|
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
|
||||||
.onInputStream(sourceInputStream) // insert encrypted data here
|
.onInputStream(sourceInputStream) // insert encrypted data here
|
||||||
.decryptWith(secretKeyDecryptor, secretKey)
|
.decryptWith(secretKeyDecryptor, secretKey)
|
||||||
.verifyWith(trustedKeyIds, senderKeys)
|
.verifyWith(trustedKeyIds, senderKeys)
|
||||||
|
|
|
@ -55,17 +55,38 @@ public class PGPainless {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an {@link EncryptionStream}, which can be used to encrypt and/or sign data using OpenPGP.
|
* Create an {@link EncryptionStream}, which can be used to encrypt and/or sign data using OpenPGP.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #encryptAndOrSign()} instead.
|
||||||
* @return builder
|
* @return builder
|
||||||
*/
|
*/
|
||||||
public static EncryptionBuilder createEncryptor() {
|
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();
|
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.
|
* Create a {@link DecryptionStream}, which can be used to decrypt and/or verify data using OpenPGP.
|
||||||
* @return builder
|
* @return builder
|
||||||
*/
|
*/
|
||||||
public static DecryptionBuilder createDecryptor() {
|
public static DecryptionBuilder decryptAndOrVerify() {
|
||||||
return new DecryptionBuilder();
|
return new DecryptionBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class DecryptAndVerifyMessageTest {
|
||||||
public void decryptMessageAndVerifySignatureTest() throws Exception {
|
public void decryptMessageAndVerifySignatureTest() throws Exception {
|
||||||
String encryptedMessage = TestKeys.MSG_SIGN_CRYPT_JULIET_JULIET;
|
String encryptedMessage = TestKeys.MSG_SIGN_CRYPT_JULIET_JULIET;
|
||||||
|
|
||||||
DecryptionStream decryptor = PGPainless.createDecryptor()
|
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
|
||||||
.onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes()))
|
.onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes()))
|
||||||
.decryptWith(new UnprotectedKeysProtector(), new PGPSecretKeyRingCollection(Collections.singleton(juliet)))
|
.decryptWith(new UnprotectedKeysProtector(), new PGPSecretKeyRingCollection(Collections.singleton(juliet)))
|
||||||
.verifyWith(Collections.singleton(new PGPPublicKeyRing(Collections.singletonList(juliet.getPublicKey()))))
|
.verifyWith(Collections.singleton(new PGPPublicKeyRing(Collections.singletonList(juliet.getPublicKey()))))
|
||||||
|
|
|
@ -137,7 +137,7 @@ public class EncryptDecryptTest {
|
||||||
|
|
||||||
ByteArrayOutputStream envelope = new ByteArrayOutputStream();
|
ByteArrayOutputStream envelope = new ByteArrayOutputStream();
|
||||||
|
|
||||||
EncryptionStream encryptor = PGPainless.createEncryptor()
|
EncryptionStream encryptor = PGPainless.encryptAndOrSign()
|
||||||
.onOutputStream(envelope)
|
.onOutputStream(envelope)
|
||||||
.toRecipients(recipientPub)
|
.toRecipients(recipientPub)
|
||||||
.usingSecureAlgorithms()
|
.usingSecureAlgorithms()
|
||||||
|
@ -165,7 +165,7 @@ public class EncryptDecryptTest {
|
||||||
// Juliet trieth to comprehend Romeos words
|
// Juliet trieth to comprehend Romeos words
|
||||||
|
|
||||||
ByteArrayInputStream envelopeIn = new ByteArrayInputStream(encryptedSecretMessage);
|
ByteArrayInputStream envelopeIn = new ByteArrayInputStream(encryptedSecretMessage);
|
||||||
DecryptionStream decryptor = PGPainless.createDecryptor()
|
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
|
||||||
.onInputStream(envelopeIn)
|
.onInputStream(envelopeIn)
|
||||||
.decryptWith(keyDecryptor, BCUtil.keyRingsToKeyRingCollection(recipientSec))
|
.decryptWith(keyDecryptor, BCUtil.keyRingsToKeyRingCollection(recipientSec))
|
||||||
.verifyWith(BCUtil.keyRingsToKeyRingCollection(senderPub))
|
.verifyWith(BCUtil.keyRingsToKeyRingCollection(senderPub))
|
||||||
|
@ -193,7 +193,7 @@ public class EncryptDecryptTest {
|
||||||
byte[] data = testMessage.getBytes();
|
byte[] data = testMessage.getBytes();
|
||||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
|
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
|
||||||
ByteArrayOutputStream dummyOut = new ByteArrayOutputStream();
|
ByteArrayOutputStream dummyOut = new ByteArrayOutputStream();
|
||||||
EncryptionStream signer = PGPainless.createEncryptor().onOutputStream(dummyOut)
|
EncryptionStream signer = PGPainless.encryptAndOrSign().onOutputStream(dummyOut)
|
||||||
.doNotEncrypt()
|
.doNotEncrypt()
|
||||||
.createDetachedSignature()
|
.createDetachedSignature()
|
||||||
.signWith(keyRingProtector, signingKeys.getSecretKeys())
|
.signWith(keyRingProtector, signingKeys.getSecretKeys())
|
||||||
|
@ -214,7 +214,7 @@ public class EncryptDecryptTest {
|
||||||
// CHECKSTYLE:ON
|
// CHECKSTYLE:ON
|
||||||
|
|
||||||
inputStream = new ByteArrayInputStream(testMessage.getBytes());
|
inputStream = new ByteArrayInputStream(testMessage.getBytes());
|
||||||
DecryptionStream verifier = PGPainless.createDecryptor().onInputStream(inputStream)
|
DecryptionStream verifier = PGPainless.decryptAndOrVerify().onInputStream(inputStream)
|
||||||
.doNotDecrypt()
|
.doNotDecrypt()
|
||||||
.verifyDetachedSignature(new ByteArrayInputStream(armorSig.getBytes()))
|
.verifyDetachedSignature(new ByteArrayInputStream(armorSig.getBytes()))
|
||||||
.verifyWith(Collections.singleton(signingKeys.getPublicKeys()))
|
.verifyWith(Collections.singleton(signingKeys.getPublicKeys()))
|
||||||
|
@ -235,7 +235,7 @@ public class EncryptDecryptTest {
|
||||||
byte[] data = testMessage.getBytes();
|
byte[] data = testMessage.getBytes();
|
||||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
|
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
|
||||||
ByteArrayOutputStream signOut = new ByteArrayOutputStream();
|
ByteArrayOutputStream signOut = new ByteArrayOutputStream();
|
||||||
EncryptionStream signer = PGPainless.createEncryptor().onOutputStream(signOut)
|
EncryptionStream signer = PGPainless.encryptAndOrSign().onOutputStream(signOut)
|
||||||
.doNotEncrypt()
|
.doNotEncrypt()
|
||||||
.signWith(keyRingProtector, signingKeys.getSecretKeys())
|
.signWith(keyRingProtector, signingKeys.getSecretKeys())
|
||||||
.asciiArmor();
|
.asciiArmor();
|
||||||
|
@ -247,7 +247,7 @@ public class EncryptDecryptTest {
|
||||||
// CHECKSTYLE:ON
|
// CHECKSTYLE:ON
|
||||||
|
|
||||||
inputStream = new ByteArrayInputStream(signOut.toByteArray());
|
inputStream = new ByteArrayInputStream(signOut.toByteArray());
|
||||||
DecryptionStream verifier = PGPainless.createDecryptor().onInputStream(inputStream)
|
DecryptionStream verifier = PGPainless.decryptAndOrVerify().onInputStream(inputStream)
|
||||||
.doNotDecrypt()
|
.doNotDecrypt()
|
||||||
.verifyWith(Collections.singleton(signingKeys.getPublicKeys()))
|
.verifyWith(Collections.singleton(signingKeys.getPublicKeys()))
|
||||||
.ignoreMissingPublicKeys()
|
.ignoreMissingPublicKeys()
|
||||||
|
|
|
@ -116,7 +116,7 @@ public class LengthTest {
|
||||||
|
|
||||||
ByteArrayOutputStream envelope = new ByteArrayOutputStream();
|
ByteArrayOutputStream envelope = new ByteArrayOutputStream();
|
||||||
|
|
||||||
OutputStream encryptor = PGPainless.createEncryptor()
|
OutputStream encryptor = PGPainless.encryptAndOrSign()
|
||||||
.onOutputStream(envelope)
|
.onOutputStream(envelope)
|
||||||
.toRecipients(recipientPub)
|
.toRecipients(recipientPub)
|
||||||
// .doNotEncrypt()
|
// .doNotEncrypt()
|
||||||
|
|
|
@ -180,7 +180,7 @@ public class ChangeSecretKeyRingPassphraseTest {
|
||||||
private void signDummyMessageWithKeysAndPassphrase(PGPKeyRing keyRing, Passphrase passphrase) throws IOException, PGPException {
|
private void signDummyMessageWithKeysAndPassphrase(PGPKeyRing keyRing, Passphrase passphrase) throws IOException, PGPException {
|
||||||
String dummyMessage = "dummy";
|
String dummyMessage = "dummy";
|
||||||
ByteArrayOutputStream dummy = new ByteArrayOutputStream();
|
ByteArrayOutputStream dummy = new ByteArrayOutputStream();
|
||||||
EncryptionStream stream = PGPainless.createEncryptor().onOutputStream(dummy)
|
EncryptionStream stream = PGPainless.encryptAndOrSign().onOutputStream(dummy)
|
||||||
.doNotEncrypt()
|
.doNotEncrypt()
|
||||||
.signWith(PasswordBasedSecretKeyRingProtector.forKey(keyRing.getSecretKeys(), passphrase), keyRing.getSecretKeys())
|
.signWith(PasswordBasedSecretKeyRingProtector.forKey(keyRing.getSecretKeys(), passphrase), keyRing.getSecretKeys())
|
||||||
.noArmor();
|
.noArmor();
|
||||||
|
|
Loading…
Reference in a new issue