Package org.bouncycastle.openpgp
Class PGPUtil
java.lang.Object
org.bouncycastle.openpgp.PGPUtil
- All Implemented Interfaces:
HashAlgorithmTags
PGP utilities.
-
Field Summary
Fields inherited from interface org.bouncycastle.bcpg.HashAlgorithmTags
DOUBLE_SHA, HAVAL_5_160, MD2, MD4, MD5, RIPEMD160, SHA1, SHA224, SHA256, SHA3_224, SHA3_256, SHA3_256_OLD, SHA3_384, SHA3_512, SHA3_512_OLD, SHA384, SHA512, SM3, TIGER_192
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
getCurveName
(org.bouncycastle.asn1.ASN1ObjectIdentifier oid) Return the EC curve name for the passed in OID.static InputStream
Obtains a stream that can be used to read PGP data from the provided stream.static String
Deprecated.unusedstatic int
getDigestIDForName
(String name) 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 boolean
isKeyBox
(byte[] data) Return true if the byte[] blob probably represents key box data.static boolean
isKeyRing
(byte[] blob) Return true if the byte[] blob probably represents key ring data.static byte[]
makeRandomKey
(int algorithm, SecureRandom random) Generates a random key for asymmetric encryption algorithm
.static void
setDefaultProvider
(String provider) Deprecated.unusedstatic 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.
-
Constructor Details
-
PGPUtil
public PGPUtil()
-
-
Method Details
-
getDigestName
Return an appropriate name for the hash algorithm represented by the passed in hash algorithm ID number.- Parameters:
hashAlgorithm
- the algorithm ID for a hash algorithm.- Returns:
- a String representation of the hash name.
- Throws:
PGPException
-
getDigestIDForName
-
getCurveName
Return the EC curve name for the passed in OID.- Parameters:
oid
- the EC curve object identifier in the PGP key- Returns:
- a string representation of the OID.
-
getSignatureName
Return an appropriate name for the signature algorithm represented by the passed in public key and hash algorithm ID numbers.- Parameters:
keyAlgorithm
- the algorithm ID for the public key algorithm used in the signature.hashAlgorithm
- the algorithm ID for the hash algorithm used.- Returns:
- a String representation of the signature name.
- Throws:
PGPException
-
getSymmetricCipherName
Return an appropriate name for the symmetric algorithm represented by the passed in symmetric algorithm ID number.- Parameters:
algorithm
- the algorithm ID for a symmetric cipher.- Returns:
- a String representation of the cipher name.
-
getDefaultProvider
Deprecated.unusedReturn the JCA/JCE provider that will be used by factory classes in situations where a provider must be determined on the fly.- Returns:
- the name of the default provider.
-
setDefaultProvider
Deprecated.unusedSet the provider to be used by the package when it is necessary to find one on the fly.- Parameters:
provider
- the name of the JCA/JCE provider to use by default.
-
isKeyRing
Return true if the byte[] blob probably represents key ring data.- Returns:
- true if data likely represents a key ring stream.
- Throws:
IOException
-
isKeyBox
Return true if the byte[] blob probably represents key box data.- Returns:
- true if data likely represents a key box stream.
- Throws:
IOException
-
makeRandomKey
Generates a random key for asymmetric encryption algorithm
.- Parameters:
algorithm
- the symmetric key algorithm identifier.random
- a source of random data.- Returns:
- a key of the length required by the specified encryption algorithm.
- Throws:
PGPException
- if the encryption algorithm is unknown.
-
writeFileToLiteralData
public static void writeFileToLiteralData(OutputStream out, char fileType, File file) throws IOException Write out the contents of the provided file as a literal data packet.- Parameters:
out
- the stream to write the literal data to.fileType
- thePGPLiteralData
type to use for the file data.file
- the file to write the contents of.- Throws:
IOException
- if an error occurs reading the file or writing to the output stream.
-
writeFileToLiteralData
public static void writeFileToLiteralData(OutputStream out, char fileType, File file, byte[] buffer) throws IOException Write out the contents of the provided file as a literal data packet in partial packet format.- Parameters:
out
- the stream to write the literal data to.fileType
- thePGPLiteralData
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.- Throws:
IOException
- if an error occurs reading the file or writing to the output stream.- See Also:
-
getDecoderStream
Obtains a stream that can be used to read PGP data from the provided stream.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.- Parameters:
in
- the stream to be checked and possibly wrapped.- Returns:
- a stream that will return PGP binary encoded data.
- Throws:
IOException
- if an error occurs reading the stream, or initialising theArmoredInputStream
.
-