Package org.pgpainless.util
Class ArmorUtils
java.lang.Object
org.pgpainless.util.ArmorUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddCommentHeader(org.bouncycastle.bcpg.ArmoredOutputStream armor, String comment) Add an ASCII armor comment header entry into theArmoredOutputStream.static voidaddHashAlgorithmHeader(org.bouncycastle.bcpg.ArmoredOutputStream armor, HashAlgorithm hashAlgorithm) Add an ASCII armor header entry about the used hash algorithm into theArmoredOutputStream.static voidaddMessageIdHeader(org.bouncycastle.bcpg.ArmoredOutputStream armor, String messageId) Add an ASCII armor message-id header entry into theArmoredOutputStream.getArmorHeaderValues(org.bouncycastle.bcpg.ArmoredInputStream armor, String headerKey) Return all ASCII armor header values of the given headerKey from the givenArmoredInputStream.getCharsetHeaderValues(org.bouncycastle.bcpg.ArmoredInputStream armor) Return all ASCII armor header values of type charset from the givenArmoredInputStream.getCommentHeaderValues(org.bouncycastle.bcpg.ArmoredInputStream armor) Extract all ASCII armor header values of type comment from the givenArmoredInputStream.static InputStreamgetDecoderStream(InputStream inputStream) Hacky workaround for #96.static List<HashAlgorithm>getHashAlgorithms(org.bouncycastle.bcpg.ArmoredInputStream armor) Return a list ofHashAlgorithmenums extracted from the hash header entries of the givenArmoredInputStream.getHashHeaderValues(org.bouncycastle.bcpg.ArmoredInputStream armor) Return all ASCII armor header values of type hash-algorithm from the givenArmoredInputStream.getMessageIdHeaderValues(org.bouncycastle.bcpg.ArmoredInputStream armor) Extract all ASCII armor header values of type message id from the givenArmoredInputStream.getVersionHeaderValues(org.bouncycastle.bcpg.ArmoredInputStream armor) Return all ASCII armor header values of type version from the givenArmoredInputStream.static org.bouncycastle.bcpg.ArmoredOutputStreamtoAsciiArmoredStream(OutputStream outputStream, MultiMap<String, String> header) Create anArmoredOutputStreamwrapping the givenOutputStream.static org.bouncycastle.bcpg.ArmoredOutputStreamtoAsciiArmoredStream(org.bouncycastle.openpgp.PGPKeyRing keyRing, OutputStream outputStream) Return anArmoredOutputStreamprepared with headers for the given key ring, which wraps the givenOutputStream.static StringtoAsciiArmoredString(byte[] bytes) Return the ASCII armored encoding of the given OpenPGP data bytes.static StringtoAsciiArmoredString(byte[] bytes, MultiMap<String, String> additionalHeaderValues) Return the ASCII armored encoding of the given OpenPGP data bytes.static StringtoAsciiArmoredString(InputStream inputStream) Return the ASCII armored encoding of theInputStreamcontaining OpenPGP data.static StringtoAsciiArmoredString(InputStream inputStream, MultiMap<String, String> additionalHeaderValues) Return the ASCII armored encoding of the OpenPGP data from the givenInputStream.static StringtoAsciiArmoredString(org.bouncycastle.openpgp.PGPPublicKey publicKey) Return the ASCII armored encoding of the givenPGPPublicKey.static StringtoAsciiArmoredString(org.bouncycastle.openpgp.PGPPublicKeyRing publicKeys) Return the ASCII armored encoding of the givenPGPPublicKeyRing.static StringtoAsciiArmoredString(org.bouncycastle.openpgp.PGPPublicKeyRingCollection publicKeyRings) Return the ASCII armored encoding of the givenPGPPublicKeyRingCollection.static StringtoAsciiArmoredString(org.bouncycastle.openpgp.PGPSecretKey secretKey) Return the ASCII armored encoding of the givenPGPSecretKey.static StringtoAsciiArmoredString(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys) Return the ASCII armored encoding of the givenPGPSecretKeyRing.static StringtoAsciiArmoredString(org.bouncycastle.openpgp.PGPSecretKeyRingCollection secretKeyRings) Return the ASCII armored encoding of the givenPGPSecretKeyRingCollection.static StringtoAsciiArmoredString(org.bouncycastle.openpgp.PGPSignature signature) Return the ASCII armored representation of the given detached signature.static StringtoAsciiArmoredString(org.bouncycastle.openpgp.PGPSignature signature, boolean export) Return the ASCII armored representation of the given detached signature.
-
Field Details
-
HEADER_COMMENT
- See Also:
-
HEADER_VERSION
- See Also:
-
HEADER_MESSAGEID
- See Also:
-
HEADER_HASH
- See Also:
-
HEADER_CHARSET
- See Also:
-
-
Method Details
-
toAsciiArmoredString
@Nonnull public static String toAsciiArmoredString(@Nonnull org.bouncycastle.openpgp.PGPSecretKey secretKey) throws IOException Return the ASCII armored encoding of the givenPGPSecretKey.- Parameters:
secretKey- secret key- Returns:
- ASCII armored encoding
- Throws:
IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static String toAsciiArmoredString(@Nonnull org.bouncycastle.openpgp.PGPPublicKey publicKey) throws IOException Return the ASCII armored encoding of the givenPGPPublicKey.- Parameters:
publicKey- public key- Returns:
- ASCII armored encoding
- Throws:
IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static String toAsciiArmoredString(@Nonnull org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys) throws IOException Return the ASCII armored encoding of the givenPGPSecretKeyRing.- Parameters:
secretKeys- secret key ring- Returns:
- ASCII armored encoding
- Throws:
IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static String toAsciiArmoredString(@Nonnull org.bouncycastle.openpgp.PGPPublicKeyRing publicKeys) throws IOException Return the ASCII armored encoding of the givenPGPPublicKeyRing.- Parameters:
publicKeys- public key ring- Returns:
- ASCII armored encoding
- Throws:
IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static String toAsciiArmoredString(@Nonnull org.bouncycastle.openpgp.PGPSecretKeyRingCollection secretKeyRings) throws IOException Return the ASCII armored encoding of the givenPGPSecretKeyRingCollection. The encoding will use per-key ASCII armors protecting eachPGPSecretKeyRingindividually. Those armors are then concatenated with newlines in between.- Parameters:
secretKeyRings- secret key ring collection- Returns:
- ASCII armored encoding
- Throws:
IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static String toAsciiArmoredString(@Nonnull org.bouncycastle.openpgp.PGPPublicKeyRingCollection publicKeyRings) throws IOException Return the ASCII armored encoding of the givenPGPPublicKeyRingCollection. The encoding will use per-key ASCII armors protecting eachPGPPublicKeyRingindividually. Those armors are then concatenated with newlines in between.- Parameters:
publicKeyRings- public key ring collection- Returns:
- ascii armored encoding
- Throws:
IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static String toAsciiArmoredString(@Nonnull org.bouncycastle.openpgp.PGPSignature signature) throws IOException Return the ASCII armored representation of the given detached signature. The signature will not be stripped of non-exportable subpackets or trust-packets. If you need to strip those (e.g. because the signature is intended to be sent to a third party), usetoAsciiArmoredString(PGPSignature, boolean)and providetrue
as boolean value.- Parameters:
signature- signature- Returns:
- ascii armored string
- Throws:
IOException- in case of an error in theArmoredOutputStream
-
toAsciiArmoredString
@Nonnull public static String toAsciiArmoredString(@Nonnull org.bouncycastle.openpgp.PGPSignature signature, boolean export) throws IOException Return the ASCII armored representation of the given detached signature. Ifexport
is true, the signature will be stripped of non-exportable subpackets or trust-packets. If it isfalse
, the signature will be encoded as-is.- Parameters:
signature- signature- Returns:
- ascii armored string
- Throws:
IOException- in case of an error in theArmoredOutputStream
-
toAsciiArmoredString
Return the ASCII armored encoding of the given OpenPGP data bytes.- Parameters:
bytes- openpgp data- Returns:
- ASCII armored encoding
- Throws:
IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static String toAsciiArmoredString(@Nonnull byte[] bytes, @Nullable MultiMap<String, String> additionalHeaderValues) throws IOExceptionReturn the ASCII armored encoding of the given OpenPGP data bytes. The ASCII armor will include headers from the header map.- Parameters:
bytes- OpenPGP dataadditionalHeaderValues- header map- Returns:
- ASCII armored encoding
- Throws:
IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static String toAsciiArmoredString(@Nonnull InputStream inputStream) throws IOException Return the ASCII armored encoding of theInputStreamcontaining OpenPGP data.- Parameters:
inputStream- input stream of OpenPGP data- Returns:
- ASCII armored encoding
- Throws:
IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static String toAsciiArmoredString(@Nonnull InputStream inputStream, @Nullable MultiMap<String, String> additionalHeaderValues) throws IOExceptionReturn the ASCII armored encoding of the OpenPGP data from the givenInputStream. The ASCII armor will include armor headers from the given header map.- Parameters:
inputStream- input stream of OpenPGP dataadditionalHeaderValues- ASCII armor header map- Returns:
- ASCII armored encoding
- Throws:
IOException- in case of an io error
-
toAsciiArmoredStream
@Nonnull public static org.bouncycastle.bcpg.ArmoredOutputStream toAsciiArmoredStream(@Nonnull org.bouncycastle.openpgp.PGPKeyRing keyRing, @Nonnull OutputStream outputStream) Return anArmoredOutputStreamprepared with headers for the given key ring, which wraps the givenOutputStream. The armored output stream can be used to encode the key ring by callingPGPKeyRing.encode(OutputStream)with the armored output stream as an argument.- Parameters:
keyRing- key ringoutputStream- wrapped output stream- Returns:
- armored output stream
-
toAsciiArmoredStream
@Nonnull public static org.bouncycastle.bcpg.ArmoredOutputStream toAsciiArmoredStream(@Nonnull OutputStream outputStream, @Nullable MultiMap<String, String> header) Create anArmoredOutputStreamwrapping the givenOutputStream. The armored output stream will be prepared with armor headers given by header. Note: Since the armored output stream is retrieved fromArmoredOutputStreamFactory.get(OutputStream), it may already come with custom headers. Hence, the header entries given by header are appended below those already populated headers.- Parameters:
outputStream- output stream to wrapheader- map of header entries- Returns:
- armored output stream
-
addHashAlgorithmHeader
public static void addHashAlgorithmHeader(@Nonnull org.bouncycastle.bcpg.ArmoredOutputStream armor, @Nonnull HashAlgorithm hashAlgorithm) Add an ASCII armor header entry about the used hash algorithm into theArmoredOutputStream.- Parameters:
armor- armored output streamhashAlgorithm- hash algorithm- See Also:
-
addCommentHeader
public static void addCommentHeader(@Nonnull org.bouncycastle.bcpg.ArmoredOutputStream armor, @Nonnull String comment) Add an ASCII armor comment header entry into theArmoredOutputStream.- Parameters:
armor- armored output streamcomment- free-text comment- See Also:
-
addMessageIdHeader
public static void addMessageIdHeader(@Nonnull org.bouncycastle.bcpg.ArmoredOutputStream armor, @Nonnull String messageId) Add an ASCII armor message-id header entry into theArmoredOutputStream.- Parameters:
armor- armored output streammessageId- message id- See Also:
-
getCommentHeaderValues
@Nonnull public static List<String> getCommentHeaderValues(@Nonnull org.bouncycastle.bcpg.ArmoredInputStream armor) Extract all ASCII armor header values of type comment from the givenArmoredInputStream.- Parameters:
armor- armored input stream- Returns:
- list of comment headers
-
getMessageIdHeaderValues
@Nonnull public static List<String> getMessageIdHeaderValues(@Nonnull org.bouncycastle.bcpg.ArmoredInputStream armor) Extract all ASCII armor header values of type message id from the givenArmoredInputStream.- Parameters:
armor- armored input stream- Returns:
- list of message-id headers
-
getHashHeaderValues
@Nonnull public static List<String> getHashHeaderValues(@Nonnull org.bouncycastle.bcpg.ArmoredInputStream armor) Return all ASCII armor header values of type hash-algorithm from the givenArmoredInputStream.- Parameters:
armor- armored input stream- Returns:
- list of hash headers
-
getHashAlgorithms
@Nonnull public static List<HashAlgorithm> getHashAlgorithms(@Nonnull org.bouncycastle.bcpg.ArmoredInputStream armor) Return a list ofHashAlgorithmenums extracted from the hash header entries of the givenArmoredInputStream.- Parameters:
armor- armored input stream- Returns:
- list of hash algorithms from the ASCII header
-
getVersionHeaderValues
@Nonnull public static List<String> getVersionHeaderValues(@Nonnull org.bouncycastle.bcpg.ArmoredInputStream armor) Return all ASCII armor header values of type version from the givenArmoredInputStream.- Parameters:
armor- armored input stream- Returns:
- list of version headers
-
getCharsetHeaderValues
@Nonnull public static List<String> getCharsetHeaderValues(@Nonnull org.bouncycastle.bcpg.ArmoredInputStream armor) Return all ASCII armor header values of type charset from the givenArmoredInputStream.- Parameters:
armor- armored input stream- Returns:
- list of charset headers
-
getArmorHeaderValues
@Nonnull public static List<String> getArmorHeaderValues(@Nonnull org.bouncycastle.bcpg.ArmoredInputStream armor, @Nonnull String headerKey) Return all ASCII armor header values of the given headerKey from the givenArmoredInputStream.- Parameters:
armor- armored input streamheaderKey- ASCII armor header key- Returns:
- list of values for the header key
-
getDecoderStream
@Nonnull public static InputStream getDecoderStream(@Nonnull InputStream inputStream) throws IOException Hacky workaround for #96. ForPGPPublicKeyRingCollection(InputStream, KeyFingerPrintCalculator)orPGPSecretKeyRingCollection(InputStream, KeyFingerPrintCalculator)to read all PGPKeyRings properly, we apparently have to make sure that theInputStreamthat is given as constructor argument is a PGPUtil.BufferedInputStreamExt. SincePGPUtil.getDecoderStream(InputStream)will return anArmoredInputStreamif the underlying input stream contains armored data, we first dearmor the data ourselves to make sure that the end-result is a PGPUtil.BufferedInputStreamExt.- Parameters:
inputStream- input stream- Returns:
- BufferedInputStreamExt
- Throws:
IOException- in case of an IO error
-