1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-01-08 19:27:57 +01:00

De-duplicate KeyPrinter class

This commit is contained in:
Paul Schaub 2020-11-18 12:20:59 +01:00
parent 4dd2b2f71a
commit 9f95e7925b

View file

@ -18,6 +18,7 @@ package org.pgpainless.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
@ -27,20 +28,22 @@ import org.bouncycastle.util.io.Streams;
public class KeyPrinter {
public static String toAsciiArmoredString(PGPSecretKeyRing secretKeys) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ArmoredOutputStream armor = new ArmoredOutputStream(out);
Streams.pipeAll(new ByteArrayInputStream(secretKeys.getEncoded()), armor);
armor.close();
return out.toString();
return toAsciiArmoredString(secretKeys.getEncoded());
}
public static String toAsciiArmoredString(PGPPublicKeyRing publicKeys) throws IOException {
return toAsciiArmoredString(publicKeys.getEncoded());
}
public static String toAsciiArmoredString(byte[] bytes) throws IOException {
return toAsciiArmoredString(new ByteArrayInputStream(bytes));
}
public static String toAsciiArmoredString(InputStream inputStream) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ArmoredOutputStream armor = new ArmoredOutputStream(out);
Streams.pipeAll(new ByteArrayInputStream(publicKeys.getEncoded()), armor);
Streams.pipeAll(inputStream, armor);
armor.close();
return out.toString();