public class PGPUtil extends Object implements HashAlgorithmTags
DOUBLE_SHA, HAVAL_5_160, MD2, MD5, RIPEMD160, SHA1, SHA224, SHA256, SHA384, SHA512, TIGER_192
Constructor and Description |
---|
PGPUtil() |
Modifier and Type | Method and Description |
---|---|
static InputStream |
getDecoderStream(InputStream in)
Obtains a stream that can be used to read PGP data from the provided stream.
|
static String |
getDefaultProvider()
Deprecated.
unused
|
static String |
getDigestName(int hashAlgorithm)
Return an appropriate name for the hash algorithm represented by the passed
in hash algorithm ID number.
|
static String |
getSignatureName(int keyAlgorithm,
int hashAlgorithm)
Return an appropriate name for the signature algorithm represented by the passed
in public key and hash algorithm ID numbers.
|
static String |
getSymmetricCipherName(int algorithm)
Return an appropriate name for the symmetric algorithm represented by the passed
in symmetric algorithm ID number.
|
static byte[] |
makeRandomKey(int algorithm,
SecureRandom random)
Generates a random key for a
symmetric encryption algorithm
. |
static void |
setDefaultProvider(String provider)
Deprecated.
unused
|
static void |
writeFileToLiteralData(OutputStream out,
char fileType,
File file)
Write out the contents of the provided file as a literal data packet.
|
static void |
writeFileToLiteralData(OutputStream out,
char fileType,
File file,
byte[] buffer)
Write out the contents of the provided file as a literal data packet in partial packet
format.
|
public static String getDigestName(int hashAlgorithm) throws PGPException
hashAlgorithm
- the algorithm ID for a hash algorithm.PGPException
public static String getSignatureName(int keyAlgorithm, int hashAlgorithm) throws PGPException
keyAlgorithm
- the algorithm ID for the public key algorithm used in the signature.hashAlgorithm
- the algorithm ID for the hash algorithm used.PGPException
public static String getSymmetricCipherName(int algorithm)
algorithm
- the algorithm ID for a symmetric cipher.public static String getDefaultProvider()
public static void setDefaultProvider(String provider)
provider
- the name of the JCA/JCE provider to use by default.public static byte[] makeRandomKey(int algorithm, SecureRandom random) throws PGPException
symmetric encryption algorithm
.algorithm
- the symmetric key algorithm identifier.random
- a source of random data.PGPException
- if the encryption algorithm is unknown.public static void writeFileToLiteralData(OutputStream out, char fileType, File file) throws IOException
out
- the stream to write the literal data to.fileType
- the PGPLiteralData
type to use for the file data.file
- the file to write the contents of.IOException
- if an error occurs reading the file or writing to the output stream.public static void writeFileToLiteralData(OutputStream out, char fileType, File file, byte[] buffer) throws IOException
out
- the stream to write the literal data to.fileType
- the PGPLiteralData
type to use for the file data.file
- the file to write the contents of.buffer
- buffer to be used to chunk the file into partial packets.IOException
- if an error occurs reading the file or writing to the output stream.PGPLiteralDataGenerator.open(OutputStream, char, String, Date, byte[]).
public static InputStream getDecoderStream(InputStream in) throws IOException
If the initial bytes of the underlying stream are binary PGP encodings, then the stream will
be returned directly, otherwise an ArmoredInputStream
is used to wrap the provided
stream and remove ASCII-Armored encoding.
in
- the stream to be checked and possibly wrapped.IOException
- if an error occurs reading the stream, or initialising the
ArmoredInputStream
.Copyright © 2017 BouncyCastle.org. All rights reserved.