Class Crypto


  • public class Crypto
    extends Object
    • Method Detail

      • generateKeys

        public static KeyPair generateKeys()
      • parseCompressedPublicKey

        public static org.bouncycastle.jce.interfaces.ECPublicKey parseCompressedPublicKey​(byte[] compressedPubKey)
                                                                                    throws CryptoException
        Throws:
        CryptoException
      • parseCompressedPrivateKey

        public static org.bouncycastle.jce.interfaces.ECPrivateKey parseCompressedPrivateKey​(byte[] compressedPrivateKey)
                                                                                      throws CryptoException
        Throws:
        CryptoException
      • sign

        public static void sign​(PrivateKey key,
                                Signable signable)
                         throws CryptoException
        Signs the given signable with the Privatekey. This will also put the resulting signature into the Signable object
        Parameters:
        key - Key to use
        signable - signature to create
        Throws:
        CryptoException - on failure
      • verifySignature

        public static boolean verifySignature​(byte[] compressedPublicKey,
                                              byte[] message,
                                              byte[] signature)
      • verifySignature

        public static boolean verifySignature​(PublicKey pubkey,
                                              byte[] message,
                                              byte[] signature)
      • verifySignature

        public static boolean verifySignature​(PublicKey publicKey,
                                              Signable content)
      • randomString

        public static String randomString​(int entropy)
        Generates a secure random HEX String with the given entropy of bytes.

        Recommendation:

        • 4 byte for small sets
        • 8 bytes for unique internal strings, e.g. hash tables
        • 16 bytes for global uniqueness, e.g. auth token

        You can also use the following probability table for the "Birthday problem", as a starting point for a suitable entropy size: Birthday problem probability table

        Parameters:
        entropy - entropy in bytes
        Returns:
        a secure random HEX String
      • randomNumber

        public static int randomNumber​(int bound)
        Generates a random number with the static SecureRandom of this class. Avoids overhead of generating a new instance of SecureRandom.
        Parameters:
        bound - the upper bound (exclusive). Must be positive.
        Returns:
        the next pseudorandom, uniformly distributed int value between zero (inclusive) and bound (exclusive) from this random number generator's sequence