1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-25 21:14:49 +02:00

Use new packet format when armoring key material

This commit is contained in:
Paul Schaub 2022-02-13 00:18:03 +01:00
parent b202972042
commit bcf8f25d21
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -17,6 +17,7 @@ import java.util.regex.Pattern;
import org.bouncycastle.bcpg.ArmoredInputStream;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.bcpg.BCPGOutputStream;
import org.bouncycastle.openpgp.PGPKeyRing;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
@ -47,22 +48,38 @@ public final class ArmorUtils {
public static String toAsciiArmoredString(PGPSecretKey secretKey) throws IOException {
MultiMap<String, String> header = keyToHeader(secretKey.getPublicKey());
return toAsciiArmoredString(secretKey.getEncoded(), header);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
BCPGOutputStream bcpgOut = new BCPGOutputStream(bytes, true);
secretKey.encode(bcpgOut);
bcpgOut.close();
return toAsciiArmoredString(bytes.toByteArray(), header);
}
public static String toAsciiArmoredString(PGPPublicKey publicKey) throws IOException {
MultiMap<String, String> header = keyToHeader(publicKey);
return toAsciiArmoredString(publicKey.getEncoded(), header);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
BCPGOutputStream bcpgOut = new BCPGOutputStream(bytes, true);
publicKey.encode(bcpgOut);
bcpgOut.close();
return toAsciiArmoredString(bytes.toByteArray(), header);
}
public static String toAsciiArmoredString(PGPSecretKeyRing secretKeys) throws IOException {
MultiMap<String, String> header = keysToHeader(secretKeys);
return toAsciiArmoredString(secretKeys.getEncoded(), header);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
BCPGOutputStream bcpgOut = new BCPGOutputStream(bytes, true);
secretKeys.encode(bcpgOut);
bcpgOut.close();
return toAsciiArmoredString(bytes.toByteArray(), header);
}
public static String toAsciiArmoredString(PGPPublicKeyRing publicKeys) throws IOException {
MultiMap<String, String> header = keysToHeader(publicKeys);
return toAsciiArmoredString(publicKeys.getEncoded(), header);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
BCPGOutputStream bcpgOut = new BCPGOutputStream(bytes, true);
publicKeys.encode(bcpgOut);
bcpgOut.close();
return toAsciiArmoredString(bytes.toByteArray(), header);
}
public static String toAsciiArmoredString(PGPSecretKeyRingCollection secretKeyRings) throws IOException {