net.corda.core.crypto

## Class CryptoUtilsKt

- net.corda.core.crypto.CryptoUtilsKt

-     public class CryptoUtilsKt

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.security.SecureRandom` | `newSecureRandom()` Get an instance of SecureRandom to avoid blocking, due to waiting for additional entropy, when possible. In this version, the NativePRNGNonBlocking is exclusively used on Linux OS to utilize dev/urandom because in high traffic /dev/random may wait for a certain amount of "noise" to be generated on the host machine before returning a result.
    `static byte[]` | `safeRandomBytes(int numOfBytes)` Generate a securely random ByteArray of requested number of bytes. Usually used for seeds, nonces and keys.
    `static byte[]` | `sign(java.security.PrivateKey $receiver, byte[] clearData)` Helper function for signing.
    `static TransactionSignature` | `sign(java.security.PrivateKey $receiver, MetaData metaData)` Helper function for signing.
    `static byte[]` | `sign(java.security.KeyPair $receiver, byte[] clearData)` Helper function to sign with a key pair.
    `static boolean` | `verify(java.security.PublicKey $receiver, byte[] signatureData, byte[] clearData)` Helper function to verify a signature.
    `static boolean` | `verify(java.security.PublicKey $receiver, TransactionSignature transactionSignature)` Helper function to verify a metadata attached signature. It is noted that the transactionSignature contains signatureData and a `class MetaData` object that contains the signer's public key and the transaction's Merkle root.
    `static boolean` | `verify(java.security.KeyPair $receiver, byte[] signatureData, byte[] clearData)` Helper function for the signers to verify their own signature.

- - ### Method Detail

    - #### sign

          public static byte[] sign(java.security.PrivateKey $receiver,
                                    byte[] clearData)

      Helper function for signing.

      Parameters:
        `clearData` - the data/message to be signed in ByteArray form (usually the Merkle root).
      Returns:
        the digital signature (in ByteArray) on the input message.
      Throws:
        - if the signature scheme is not supported for this private key.
        - if the private key is invalid.
        - if signing is not possible due to malformed data or private key.

    - #### sign

          public static TransactionSignature sign(java.security.PrivateKey $receiver,
                                                  MetaData metaData)

      Helper function for signing.

      Returns:
        a DSWithMetaDataFull object.
      Throws:
        - if the signature scheme is not supported for this private key.
        - if the private key is invalid.
        - if signing is not possible due to malformed data or private key.

    - #### sign

          public static byte[] sign(java.security.KeyPair $receiver,
                                    byte[] clearData)

      Helper function to sign with a key pair.

      Parameters:
        `clearData` - the data/message to be signed in ByteArray form (usually the Merkle root).
      Returns:
        the digital signature (in ByteArray) on the input message.
      Throws:
        - if the signature scheme is not supported for this private key.
        - if the private key is invalid.
        - if signing is not possible due to malformed data or private key.

    - #### verify

          public static boolean verify(java.security.PublicKey $receiver,
                                       byte[] signatureData,
                                       byte[] clearData)

      Helper function to verify a signature.

      Parameters:
        `signatureData` - the signature on a message.
        `clearData` - the clear data/message that was signed (usually the Merkle root).
      Throws:
        - if the key is invalid.
        - if this signatureData object is not initialized properly, the passed-in signatureData is improperly encoded or of the wrong type, if this signatureData algorithm is unable to process the input data provided, etc.
        - if the signature scheme is not supported for this private key or if any of the clear or signature data is empty.

    - #### verify

          public static boolean verify(java.security.PublicKey $receiver,
                                       TransactionSignature transactionSignature)

      Helper function to verify a metadata attached signature. It is noted that the transactionSignature contains signatureData and a `class MetaData` object that contains the signer's public key and the transaction's Merkle root.

      Parameters:
        `transactionSignature` - a `class TransactionSignature` object that .
      Throws:
        - if the key is invalid.
        - if this signatureData object is not initialized properly, the passed-in signatureData is improperly encoded or of the wrong type, if this signatureData algorithm is unable to process the input data provided, etc.
        - if the signature scheme is not supported for this private key or if any of the clear or signature data is empty.
      See Also:
        `class MetaData`

    - #### verify

          public static boolean verify(java.security.KeyPair $receiver,
                                       byte[] signatureData,
                                       byte[] clearData)

      Helper function for the signers to verify their own signature.

      Parameters:
        `clearData` - the clear data/message that was signed (usually the Merkle root).
      Throws:
        - if the key is invalid.
        - if this signatureData object is not initialized properly, the passed-in signatureData is improperly encoded or of the wrong type, if this signatureData algorithm is unable to process the input data provided, etc.
        - if the signature scheme is not supported for this private key or if any of the clear or signature data is empty.

    - #### safeRandomBytes

          public static byte[] safeRandomBytes(int numOfBytes)

      Generate a securely random ByteArray of requested number of bytes. Usually used for seeds, nonces and keys.

      Parameters:
        `numOfBytes` - how many random bytes to output.
      Returns:
        a random ByteArray.
      Throws:
        - thrown if "NativePRNGNonBlocking" is not supported on the JVM or if no strong SecureRandom implementations are available or if Security.getProperty("securerandom.strongAlgorithms") is null or empty, which should never happen and suggests an unusual JVM or non-standard Java library.

    - #### newSecureRandom

          public static java.security.SecureRandom newSecureRandom()

      Get an instance of SecureRandom to avoid blocking, due to waiting for additional entropy, when possible. In this version, the NativePRNGNonBlocking is exclusively used on Linux OS to utilize dev/urandom because in high traffic /dev/random may wait for a certain amount of "noise" to be generated on the host machine before returning a result.

      On Solaris, Linux, and OS X, if the entropy gathering device in java.security is set to file:/dev/urandom or file:/dev/random, then NativePRNG is preferred to SHA1PRNG. Otherwise, SHA1PRNG is preferred.

      Returns:
        a SecureRandom object.
      Throws:
        - thrown if "NativePRNGNonBlocking" is not supported on the JVM or if no strong SecureRandom implementations are available or if Security.getProperty("securerandom.strongAlgorithms") is null or empty, which should never happen and suggests an unusual JVM or non-standard Java library.
      See Also:
        SecureRandom