Package org.pgpainless.util
Class ArmorUtils
- java.lang.Object
-
- org.pgpainless.util.ArmorUtils
-
public final class ArmorUtils extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringHEADER_CHARSETstatic java.lang.StringHEADER_COMMENTstatic java.lang.StringHEADER_HASHstatic java.lang.StringHEADER_MESSAGEIDstatic java.lang.StringHEADER_VERSION
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidaddCommentHeader(org.bouncycastle.bcpg.ArmoredOutputStream armor, java.lang.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, java.lang.String messageId)Add an ASCII armor message-id header entry into theArmoredOutputStream.static org.bouncycastle.bcpg.ArmoredOutputStreamcreateArmoredOutputStreamFor(org.bouncycastle.openpgp.PGPKeyRing keyRing, java.io.OutputStream outputStream)Deprecated.usetoAsciiArmoredStream(PGPKeyRing, OutputStream)instead TODO: Remove in 1.2.Xstatic java.util.List<java.lang.String>getArmorHeaderValues(org.bouncycastle.bcpg.ArmoredInputStream armor, java.lang.String headerKey)Return all ASCII armor header values of the given headerKey from the givenArmoredInputStream.static java.util.List<java.lang.String>getCharsetHeaderValues(org.bouncycastle.bcpg.ArmoredInputStream armor)Return all ASCII armor header values of type charset from the givenArmoredInputStream.static java.util.List<java.lang.String>getCommentHeaderValues(org.bouncycastle.bcpg.ArmoredInputStream armor)Extract all ASCII armor header values of type comment from the givenArmoredInputStream.static java.io.InputStreamgetDecoderStream(java.io.InputStream inputStream)Hacky workaround for #96.static java.util.List<HashAlgorithm>getHashAlgorithms(org.bouncycastle.bcpg.ArmoredInputStream armor)Return a list ofHashAlgorithmenums extracted from the hash header entries of the givenArmoredInputStream.static java.util.List<java.lang.String>getHashHeaderValues(org.bouncycastle.bcpg.ArmoredInputStream armor)Return all ASCII armor header values of type hash-algorithm from the givenArmoredInputStream.static java.util.List<java.lang.String>getMessageIdHeaderValues(org.bouncycastle.bcpg.ArmoredInputStream armor)Extract all ASCII armor header values of type message id from the givenArmoredInputStream.static java.util.List<java.lang.String>getVersionHeaderValues(org.bouncycastle.bcpg.ArmoredInputStream armor)Return all ASCII armor header values of type version from the givenArmoredInputStream.static org.bouncycastle.bcpg.ArmoredOutputStreamtoAsciiArmoredStream(java.io.OutputStream outputStream, MultiMap<java.lang.String,java.lang.String> header)Create anArmoredOutputStreamwrapping the givenOutputStream.static org.bouncycastle.bcpg.ArmoredOutputStreamtoAsciiArmoredStream(org.bouncycastle.openpgp.PGPKeyRing keyRing, java.io.OutputStream outputStream)Return anArmoredOutputStreamprepared with headers for the given key ring, which wraps the givenOutputStream.static java.lang.StringtoAsciiArmoredString(byte[] bytes)Return the ASCII armored encoding of the given OpenPGP data bytes.static java.lang.StringtoAsciiArmoredString(byte[] bytes, MultiMap<java.lang.String,java.lang.String> additionalHeaderValues)Return the ASCII armored encoding of the given OpenPGP data bytes.static java.lang.StringtoAsciiArmoredString(java.io.InputStream inputStream)Return the ASCII armored encoding of theInputStreamcontaining OpenPGP data.static java.lang.StringtoAsciiArmoredString(java.io.InputStream inputStream, MultiMap<java.lang.String,java.lang.String> additionalHeaderValues)Return the ASCII armored encoding of the OpenPGP data from the givenInputStream.static java.lang.StringtoAsciiArmoredString(org.bouncycastle.openpgp.PGPPublicKey publicKey)Return the ASCII armored encoding of the givenPGPPublicKey.static java.lang.StringtoAsciiArmoredString(org.bouncycastle.openpgp.PGPPublicKeyRing publicKeys)Return the ASCII armored encoding of the givenPGPPublicKeyRing.static java.lang.StringtoAsciiArmoredString(org.bouncycastle.openpgp.PGPPublicKeyRingCollection publicKeyRings)Return the ASCII armored encoding of the givenPGPPublicKeyRingCollection.static java.lang.StringtoAsciiArmoredString(org.bouncycastle.openpgp.PGPSecretKey secretKey)Return the ASCII armored encoding of the givenPGPSecretKey.static java.lang.StringtoAsciiArmoredString(org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys)Return the ASCII armored encoding of the givenPGPSecretKeyRing.static java.lang.StringtoAsciiArmoredString(org.bouncycastle.openpgp.PGPSecretKeyRingCollection secretKeyRings)Return the ASCII armored encoding of the givenPGPSecretKeyRingCollection.
-
-
-
Field Detail
-
HEADER_COMMENT
public static final java.lang.String HEADER_COMMENT
- See Also:
- Constant Field Values
-
HEADER_VERSION
public static final java.lang.String HEADER_VERSION
- See Also:
- Constant Field Values
-
HEADER_MESSAGEID
public static final java.lang.String HEADER_MESSAGEID
- See Also:
- Constant Field Values
-
HEADER_HASH
public static final java.lang.String HEADER_HASH
- See Also:
- Constant Field Values
-
HEADER_CHARSET
public static final java.lang.String HEADER_CHARSET
- See Also:
- Constant Field Values
-
-
Method Detail
-
toAsciiArmoredString
@Nonnull public static java.lang.String toAsciiArmoredString(@Nonnull org.bouncycastle.openpgp.PGPSecretKey secretKey) throws java.io.IOExceptionReturn the ASCII armored encoding of the givenPGPSecretKey.- Parameters:
secretKey- secret key- Returns:
- ASCII armored encoding
- Throws:
java.io.IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static java.lang.String toAsciiArmoredString(@Nonnull org.bouncycastle.openpgp.PGPPublicKey publicKey) throws java.io.IOExceptionReturn the ASCII armored encoding of the givenPGPPublicKey.- Parameters:
publicKey- public key- Returns:
- ASCII armored encoding
- Throws:
java.io.IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static java.lang.String toAsciiArmoredString(@Nonnull org.bouncycastle.openpgp.PGPSecretKeyRing secretKeys) throws java.io.IOExceptionReturn the ASCII armored encoding of the givenPGPSecretKeyRing.- Parameters:
secretKeys- secret key ring- Returns:
- ASCII armored encoding
- Throws:
java.io.IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static java.lang.String toAsciiArmoredString(@Nonnull org.bouncycastle.openpgp.PGPPublicKeyRing publicKeys) throws java.io.IOExceptionReturn the ASCII armored encoding of the givenPGPPublicKeyRing.- Parameters:
publicKeys- public key ring- Returns:
- ASCII armored encoding
- Throws:
java.io.IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static java.lang.String toAsciiArmoredString(@Nonnull org.bouncycastle.openpgp.PGPSecretKeyRingCollection secretKeyRings) throws java.io.IOExceptionReturn 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:
java.io.IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static java.lang.String toAsciiArmoredString(@Nonnull org.bouncycastle.openpgp.PGPPublicKeyRingCollection publicKeyRings) throws java.io.IOExceptionReturn 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:
java.io.IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static java.lang.String toAsciiArmoredString(@Nonnull byte[] bytes) throws java.io.IOExceptionReturn the ASCII armored encoding of the given OpenPGP data bytes.- Parameters:
bytes- openpgp data- Returns:
- ASCII armored encoding
- Throws:
java.io.IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static java.lang.String toAsciiArmoredString(@Nonnull byte[] bytes, @Nullable MultiMap<java.lang.String,java.lang.String> additionalHeaderValues) throws java.io.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:
java.io.IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static java.lang.String toAsciiArmoredString(@Nonnull java.io.InputStream inputStream) throws java.io.IOExceptionReturn the ASCII armored encoding of theInputStreamcontaining OpenPGP data.- Parameters:
inputStream- input stream of OpenPGP data- Returns:
- ASCII armored encoding
- Throws:
java.io.IOException- in case of an io error
-
toAsciiArmoredString
@Nonnull public static java.lang.String toAsciiArmoredString(@Nonnull java.io.InputStream inputStream, @Nullable MultiMap<java.lang.String,java.lang.String> additionalHeaderValues) throws java.io.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:
java.io.IOException- in case of an io error
-
toAsciiArmoredStream
@Nonnull public static org.bouncycastle.bcpg.ArmoredOutputStream toAsciiArmoredStream(@Nonnull org.bouncycastle.openpgp.PGPKeyRing keyRing, @Nonnull java.io.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 java.io.OutputStream outputStream, @Nullable MultiMap<java.lang.String,java.lang.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
-
createArmoredOutputStreamFor
@Deprecated @Nonnull public static org.bouncycastle.bcpg.ArmoredOutputStream createArmoredOutputStreamFor(@Nonnull org.bouncycastle.openpgp.PGPKeyRing keyRing, @Nonnull java.io.OutputStream outputStream)Deprecated.usetoAsciiArmoredStream(PGPKeyRing, OutputStream)instead TODO: Remove in 1.2.XReturn 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
-
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:
- RFC 4880 - OpenPGP Message Format §6.2. Forming ASCII Armor
-
addCommentHeader
public static void addCommentHeader(@Nonnull org.bouncycastle.bcpg.ArmoredOutputStream armor, @Nonnull java.lang.String comment)Add an ASCII armor comment header entry into theArmoredOutputStream.- Parameters:
armor- armored output streamcomment- free-text comment- See Also:
- RFC 4880 - OpenPGP Message Format §6.2. Forming ASCII Armor
-
addMessageIdHeader
public static void addMessageIdHeader(@Nonnull org.bouncycastle.bcpg.ArmoredOutputStream armor, @Nonnull java.lang.String messageId)Add an ASCII armor message-id header entry into theArmoredOutputStream.- Parameters:
armor- armored output streammessageId- message id- See Also:
- RFC 4880 - OpenPGP Message Format §6.2. Forming ASCII Armor
-
getCommentHeaderValues
@Nonnull public static java.util.List<java.lang.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 java.util.List<java.lang.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 java.util.List<java.lang.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 java.util.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 java.util.List<java.lang.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 java.util.List<java.lang.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 java.util.List<java.lang.String> getArmorHeaderValues(@Nonnull org.bouncycastle.bcpg.ArmoredInputStream armor, @Nonnull java.lang.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 java.io.InputStream getDecoderStream(@Nonnull java.io.InputStream inputStream) throws java.io.IOExceptionHacky 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:
java.io.IOException- in case of an IO error
-
-