Class TOMUtil


  • public class TOMUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      TOMUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String byteArrayToString​(byte[] b)  
      static java.lang.String bytesToHex​(byte[] bytes)  
      static byte[] computeHash​(byte[] data)  
      static byte[] computeHashOfCollection​(java.util.Collection<TOMMessage> messages)
      Computes a hash for a collection of TOM messages
      static boolean equalsHash​(byte[] h1, byte[] h2)  
      static javax.crypto.spec.PBEKeySpec generateKeySpec​(char[] password)  
      static byte[] getBytes​(java.lang.Object o)  
      static java.security.MessageDigest getHashEngine()  
      static java.lang.Object getObject​(byte[] b)  
      static javax.crypto.SecretKeyFactory getSecretFactory()  
      static java.security.Signature getSigEngine()  
      static void init​(java.lang.String secretAlgorithm, java.lang.String sigAlgorithm, java.lang.String hashAlgorithm, java.lang.String secretAlgorithmProvider, java.lang.String sigAlgorithmProvider, java.lang.String hashAlgorithmProvider)  
      static byte[] signMessage​(java.security.PrivateKey key, byte[] message)
      Sign a message.
      static boolean verifySigForBenchmark​(java.security.Signature initializedSignatureEngine, byte[] message, byte[] signature)  
      static boolean verifySignature​(java.security.PublicKey key, byte[] message, byte[] signature)
      Verify the signature of a message.
      static boolean verifySignature​(java.security.Signature initializedSignatureEngine, byte[] message, byte[] signature)
      Verify the signature of a message.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TOMUtil

        public TOMUtil()
    • Method Detail

      • init

        public static void init​(java.lang.String secretAlgorithm,
                                java.lang.String sigAlgorithm,
                                java.lang.String hashAlgorithm,
                                java.lang.String secretAlgorithmProvider,
                                java.lang.String sigAlgorithmProvider,
                                java.lang.String hashAlgorithmProvider)
      • getBytes

        public static byte[] getBytes​(java.lang.Object o)
      • getObject

        public static java.lang.Object getObject​(byte[] b)
      • signMessage

        public static byte[] signMessage​(java.security.PrivateKey key,
                                         byte[] message)
        Sign a message.
        Parameters:
        key - the private key to be used to generate the signature
        message - the message to be signed
        Returns:
        the signature
      • verifySignature

        public static boolean verifySignature​(java.security.PublicKey key,
                                              byte[] message,
                                              byte[] signature)
        Verify the signature of a message.
        Parameters:
        key - the public key to be used to verify the signature
        message - the signed message
        signature - the signature to be verified
        Returns:
        true if the signature is valid, false otherwise
      • verifySigForBenchmark

        public static boolean verifySigForBenchmark​(java.security.Signature initializedSignatureEngine,
                                                    byte[] message,
                                                    byte[] signature)
      • verifySignature

        public static boolean verifySignature​(java.security.Signature initializedSignatureEngine,
                                              byte[] message,
                                              byte[] signature)
                                       throws java.security.SignatureException
        Verify the signature of a message.
        Parameters:
        initializedSignatureEngine - a signature engine already initialized for verification
        message - the signed message
        signature - the signature to be verified
        Returns:
        true if the signature is valid, false otherwise
        Throws:
        java.security.SignatureException
      • byteArrayToString

        public static java.lang.String byteArrayToString​(byte[] b)
      • equalsHash

        public static boolean equalsHash​(byte[] h1,
                                         byte[] h2)
      • computeHash

        public static final byte[] computeHash​(byte[] data)
      • getSigEngine

        public static java.security.Signature getSigEngine()
                                                    throws java.security.NoSuchAlgorithmException
        Throws:
        java.security.NoSuchAlgorithmException
      • getHashEngine

        public static java.security.MessageDigest getHashEngine()
                                                         throws java.security.NoSuchAlgorithmException
        Throws:
        java.security.NoSuchAlgorithmException
      • getSecretFactory

        public static javax.crypto.SecretKeyFactory getSecretFactory()
                                                              throws java.security.NoSuchAlgorithmException
        Throws:
        java.security.NoSuchAlgorithmException
      • generateKeySpec

        public static javax.crypto.spec.PBEKeySpec generateKeySpec​(char[] password)
                                                            throws java.security.NoSuchAlgorithmException
        Throws:
        java.security.NoSuchAlgorithmException
      • computeHashOfCollection

        public static byte[] computeHashOfCollection​(java.util.Collection<TOMMessage> messages)
        Computes a hash for a collection of TOM messages
        Parameters:
        messages - TOM messages
        Returns:
        hash
      • bytesToHex

        public static java.lang.String bytesToHex​(byte[] bytes)