mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 18:59:39 +02:00
Allow encryption and decryption using symmetric passphrases in the main API
This commit is contained in:
parent
ce4f98423f
commit
7d374f10a7
10 changed files with 303 additions and 84 deletions
|
@ -15,6 +15,17 @@
|
|||
*/
|
||||
package org.pgpainless.sop.commands;
|
||||
|
||||
import static org.pgpainless.sop.Print.err_ln;
|
||||
import static org.pgpainless.sop.Print.print_ln;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKey;
|
||||
|
@ -32,17 +43,6 @@ import org.pgpainless.key.protection.PassphraseMapKeyRingProtector;
|
|||
import org.pgpainless.util.Passphrase;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static org.pgpainless.sop.Print.err_ln;
|
||||
import static org.pgpainless.sop.Print.print_ln;
|
||||
|
||||
@CommandLine.Command(name = "encrypt",
|
||||
description = "Encrypt a message from standard input")
|
||||
public class Encrypt implements Runnable {
|
||||
|
@ -107,6 +107,11 @@ public class Encrypt implements Runnable {
|
|||
System.exit(1);
|
||||
}
|
||||
}
|
||||
Passphrase[] passphraseArray = new Passphrase[withPassword.length];
|
||||
for (int i = 0; i < withPassword.length; i++) {
|
||||
String password = withPassword[i];
|
||||
passphraseArray[i] = Passphrase.fromPassword(password);
|
||||
}
|
||||
|
||||
Map<Long, Passphrase> passphraseMap = new HashMap<>();
|
||||
Scanner scanner = null;
|
||||
|
@ -137,6 +142,8 @@ public class Encrypt implements Runnable {
|
|||
EncryptionBuilderInterface.DetachedSign builder = PGPainless.encryptAndOrSign()
|
||||
.onOutputStream(System.out)
|
||||
.toRecipients(publicKeys)
|
||||
.and()
|
||||
.forPassphrases(passphraseArray)
|
||||
.usingSecureAlgorithms();
|
||||
EncryptionBuilderInterface.Armor builder_armor;
|
||||
if (signWith.length != 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue