Top Description Inners Fields Constructors Methods
org.bouncycastle.openpgp

public Class PGPUtil

extends Object
implements HashAlgorithmTags
Class Inheritance
All Implemented Interfaces
org.bouncycastle.bcpg.HashAlgorithmTags
Imports
java.io.BufferedInputStream, .ByteArrayInputStream, .File, .FileInputStream, .IOException, .InputStream, .OutputStream, java.security.SecureRandom, java.util.Date, .HashMap, .Map, org.bouncycastle.asn1.ASN1Integer, .ASN1ObjectIdentifier, .ASN1Sequence, org.bouncycastle.asn1.sec.SECObjectIdentifiers, org.bouncycastle.asn1.x9.ECNamedCurveTable, org.bouncycastle.bcpg.ArmoredInputStream, .BCPGInputStream, .HashAlgorithmTags, .MPInteger, .PacketTags, .PublicKeyAlgorithmTags, .SymmetricKeyAlgorithmTags, org.bouncycastle.util.Arrays, .Integers, .Strings, org.bouncycastle.util.encoders.Base64, .DecoderException

PGP utilities.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static String
private static Map<String, Integer>
private static Map<ASN1ObjectIdentifier, String>
private static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv static MPInteger[]
dsaSigToMpi(byte[] encoding)

public static String

Returns:

a string representation of the OID.
getCurveName
(ASN1ObjectIdentifier
the EC curve object identifier in the PGP key
oid
)

Return the EC curve name for the passed in OID.

public static InputStream

Returns:

a stream that will return PGP binary encoded data.
getDecoderStream
(InputStream
the stream to be checked and possibly wrapped.
in
)

Obtains a stream that can be used to read PGP data from the provided stream.

public static String

Returns:

the name of the default provider.
getDefaultProvider
()

Deprecated unused
Return the JCA/JCE provider that will be used by factory classes in situations where a provider must be determined on the fly.
public static int
public static String

Returns:

a String representation of the hash name.
getDigestName
(int
the algorithm ID for a hash algorithm.
hashAlgorithm
)

Return an appropriate name for the hash algorithm represented by the passed in hash algorithm ID number.

public static String

Returns:

a String representation of the signature name.
getSignatureName
(int
the algorithm ID for the public key algorithm used in the signature.
keyAlgorithm
,
int
the algorithm ID for the hash algorithm used.
hashAlgorithm
)

Return an appropriate name for the signature algorithm represented by the passed in public key and hash algorithm ID numbers.

public static String

Returns:

a String representation of the cipher name.
getSymmetricCipherName
(int
the algorithm ID for a symmetric cipher.
algorithm
)

Return an appropriate name for the symmetric algorithm represented by the passed in symmetric algorithm ID number.

public static boolean

Returns:

true if data likely represents a key box stream.
isKeyBox
(byte[] data)

Return true if the byte[] blob probably represents key box data.

public static boolean

Returns:

true if data likely represents a key ring stream.
isKeyRing
(byte[] blob)

Return true if the byte[] blob probably represents key ring data.

private static boolean
public static byte[]

Returns:

a key of the length required by the specified encryption algorithm.
makeRandomKey
(int
the symmetric key algorithm identifier.
algorithm
,
SecureRandom
a source of random data.
random
)

Generates a random key for a symmetric encryption algorithm .

pack-priv static void
pipeFileContents(File file, OutputStream pOut, int bufferSize)

public static void
setDefaultProvider(String
the name of the JCA/JCE provider to use by default.
provider
)

Deprecated unused
Set the provider to be used by the package when it is necessary to find one on the fly.
public static void
writeFileToLiteralData(OutputStream
the stream to write the literal data to.
out
,
char
the PGPLiteralData type to use for the file data.
fileType
,
File
the file to write the contents of.
file
)

Write out the contents of the provided file as a literal data packet.

public static void
writeFileToLiteralData(OutputStream
the stream to write the literal data to.
out
,
char
the PGPLiteralData type to use for the file data.
fileType
,
File
the file to write the contents of.
file
,
byte[]
buffer to be used to chunk the file into partial packets.
buffer
)

Write out the contents of the provided file as a literal data packet in partial packet format.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defProviderback to summary
private static String defProvider
nameToHashIdback to summary
private static Map<String, Integer> nameToHashId
oidToNameback to summary
private static Map<ASN1ObjectIdentifier, String> oidToName
READ_AHEADback to summary
private static final int READ_AHEAD

Constructor Detail

PGPUtilback to summary
public PGPUtil()

Method Detail

dsaSigToMpiback to summary
pack-priv static MPInteger[] dsaSigToMpi(byte[] encoding) throws PGPException
getCurveNameback to summary
public static String getCurveName(ASN1ObjectIdentifier oid)

Return the EC curve name for the passed in OID.

Parameters
oid:ASN1ObjectIdentifier

the EC curve object identifier in the PGP key

Returns:String

a string representation of the OID.

getDecoderStreamback to summary
public static InputStream getDecoderStream(InputStream in) throws IOException

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:InputStream

the stream to be checked and possibly wrapped.

Returns:InputStream

a stream that will return PGP binary encoded data.

Exceptions
IOException:
if an error occurs reading the stream, or initialising the ArmoredInputStream.
getDefaultProviderback to summary
public static String getDefaultProvider()

Deprecated

unused

Return the JCA/JCE provider that will be used by factory classes in situations where a provider must be determined on the fly.

Returns:String

the name of the default provider.

getDigestIDForNameback to summary
public static int getDigestIDForName(String name)
getDigestNameback to summary
public static String getDigestName(int hashAlgorithm) throws PGPException

Return an appropriate name for the hash algorithm represented by the passed in hash algorithm ID number.

Parameters
hashAlgorithm:int

the algorithm ID for a hash algorithm.

Returns:String

a String representation of the hash name.

getSignatureNameback to summary
public static String getSignatureName(int keyAlgorithm, int hashAlgorithm) throws PGPException

Return an appropriate name for the signature algorithm represented by the passed in public key and hash algorithm ID numbers.

Parameters
keyAlgorithm:int

the algorithm ID for the public key algorithm used in the signature.

hashAlgorithm:int

the algorithm ID for the hash algorithm used.

Returns:String

a String representation of the signature name.

getSymmetricCipherNameback to summary
public static String getSymmetricCipherName(int algorithm)

Return an appropriate name for the symmetric algorithm represented by the passed in symmetric algorithm ID number.

Parameters
algorithm:int

the algorithm ID for a symmetric cipher.

Returns:String

a String representation of the cipher name.

isKeyBoxback to summary
public static boolean isKeyBox(byte[] data) throws IOException

Return true if the byte[] blob probably represents key box data.

Returns:boolean

true if data likely represents a key box stream.

isKeyRingback to summary
public static boolean isKeyRing(byte[] blob) throws IOException

Return true if the byte[] blob probably represents key ring data.

Returns:boolean

true if data likely represents a key ring stream.

isPossiblyBase64back to summary
private static boolean isPossiblyBase64(int ch)
makeRandomKeyback to summary
public static byte[] makeRandomKey(int algorithm, SecureRandom random) throws PGPException

Generates a random key for a symmetric encryption algorithm .

Parameters
algorithm:int

the symmetric key algorithm identifier.

random:SecureRandom

a source of random data.

Returns:byte[]

a key of the length required by the specified encryption algorithm.

Exceptions
PGPException:
if the encryption algorithm is unknown.
pipeFileContentsback to summary
pack-priv static void pipeFileContents(File file, OutputStream pOut, int bufferSize) throws IOException
setDefaultProviderback to summary
public static void setDefaultProvider(String provider)

Deprecated

unused

Set the provider to be used by the package when it is necessary to find one on the fly.

Parameters
provider:String

the name of the JCA/JCE provider to use by default.

writeFileToLiteralDataback to summary
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:OutputStream

the stream to write the literal data to.

fileType:char

the PGPLiteralData type to use for the file data.

file:File

the file to write the contents of.

Exceptions
IOException:
if an error occurs reading the file or writing to the output stream.
writeFileToLiteralDataback to summary
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:OutputStream

the stream to write the literal data to.

fileType:char

the PGPLiteralData type to use for the file data.

file:File

the file to write the contents of.

buffer:byte[]

buffer to be used to chunk the file into partial packets.

Exceptions
IOException:
if an error occurs reading the file or writing to the output stream.
See Also
PGPLiteralDataGenerator#open(OutputStream, char, String, Date, byte[])
org.bouncycastle.openpgp back to summary

pack-priv Class PGPUtil.BufferedInputStreamExt

extends BufferedInputStream
Class Inheritance

Field Summary

Inherited from java.io.BufferedInputStream:
bufcountmarklimitmarkpospos

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public synchronized int
available()

Overrides java.io.BufferedInputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.
Inherited from java.io.BufferedInputStream:
closemarkmarkSupportedreadreadresetskiptransferTo

Constructor Detail

BufferedInputStreamExtback to summary
pack-priv BufferedInputStreamExt(InputStream input)

Method Detail

availableback to summary
public synchronized int available() throws IOException

Overrides java.io.BufferedInputStream.available.

Doc from java.io.BufferedInputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. The next invocation might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

This method returns the sum of the number of bytes remaining to be read in the buffer (count - pos) and the result of calling the in.available().

Returns:int

an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking.

Exceptions
IOException:
if this input stream has been closed by invoking its close() method, or an I/O error occurs.