mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-01-09 11:48:00 +01:00
De-duplicate KeyPrinter class
This commit is contained in:
parent
4dd2b2f71a
commit
9f95e7925b
1 changed files with 11 additions and 8 deletions
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue