PGPUtil
Date: 2016-06-23

org.bouncycastle.openpgp

## Class PGPUtil

- java.lang.Object
- - org.bouncycastle.openpgp.PGPUtil

- All Implemented Interfaces:
    HashAlgorithmTags

      public class PGPUtil
      extends java.lang.Object
      implements HashAlgorithmTags

  PGP utilities.

- - ### Field Summary

    - ### Fields inherited from interface org.bouncycastle.bcpg.HashAlgorithmTags

      `DOUBLE_SHA, HAVAL_5_160, MD2, MD5, RIPEMD160, SHA1, SHA224, SHA256, SHA384, SHA512, TIGER_192`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PGPUtil()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.io.InputStream` | `getDecoderStream(java.io.InputStream in)` Obtains a stream that can be used to read PGP data from the provided stream.
    `static java.lang.String` | `getDefaultProvider()` Deprecated. unused
    `static byte[]` | `makeRandomKey(int algorithm, java.security.SecureRandom random)` Generates a random key for a `symmetric encryption algorithm` .
    `static void` | `setDefaultProvider(java.lang.String provider)` Deprecated. unused
    `static void` | `writeFileToLiteralData(java.io.OutputStream out, char fileType, java.io.File file)` Write out the contents of the provided file as a literal data packet.
    `static void` | `writeFileToLiteralData(java.io.OutputStream out, char fileType, java.io.File file, byte[] buffer)` Write out the contents of the provided file as a literal data packet in partial packet format.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PGPUtil

          public PGPUtil()

  - ### Method Detail

    - #### getDefaultProvider

          public static java.lang.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:
        the name of the default provider.

    - #### setDefaultProvider

          public static void setDefaultProvider(java.lang.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` - the name of the JCA/JCE provider to use by default.

    - #### makeRandomKey

          public static byte[] makeRandomKey(int algorithm,
                             java.security.SecureRandom random)
                                      throws PGPException

      Generates a random key for a `symmetric 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(java.io.OutputStream out,
                                    char fileType,
                                    java.io.File file)
                                             throws java.io.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` - the `PGPLiteralData` type to use for the file data.
        `file` - the file to write the contents of.
      Throws:
        `java.io.IOException` - if an error occurs reading the file or writing to the output stream.

    - #### writeFileToLiteralData

          public static void writeFileToLiteralData(java.io.OutputStream out,
                                    char fileType,
                                    java.io.File file,
                                    byte[] buffer)
                                             throws java.io.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` - 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.
      Throws:
        `java.io.IOException` - if an error occurs reading the file or writing to the output stream.
      See Also:
        `PGPLiteralDataGenerator.open(OutputStream, char, String, Date, byte[]).`

    - #### getDecoderStream

          public static java.io.InputStream getDecoderStream(java.io.InputStream in)
                                                      throws java.io.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` - the stream to be checked and possibly wrapped.
      Returns:
        a stream that will return PGP binary encoded data.
      Throws:
        `java.io.IOException` - if an error occurs reading the stream, or initalising the `ArmoredInputStream`.