public class CryptoUtilsKt
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.
|
public static byte[] sign(java.security.PrivateKey $receiver, byte[] clearData)
Helper function for signing.
clearData
- the data/message to be signed in ByteArray form (usually the Merkle root).public static TransactionSignature sign(java.security.PrivateKey $receiver, MetaData metaData)
Helper function for signing.
public static byte[] sign(java.security.KeyPair $receiver, byte[] clearData)
Helper function to sign with a key pair.
clearData
- the data/message to be signed in ByteArray form (usually the Merkle root).public static boolean verify(java.security.PublicKey $receiver, byte[] signatureData, byte[] clearData)
Helper function to verify a signature.
signatureData
- the signature on a message.clearData
- the clear data/message that was signed (usually the Merkle root).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.
transactionSignature
- a class TransactionSignature
object that .class MetaData
public static boolean verify(java.security.KeyPair $receiver, byte[] signatureData, byte[] clearData)
Helper function for the signers to verify their own signature.
clearData
- the clear data/message that was signed (usually the Merkle root).public static byte[] safeRandomBytes(int numOfBytes)
Generate a securely random ByteArray of requested number of bytes. Usually used for seeds, nonces and keys.
numOfBytes
- how many random bytes to output.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.