Package bftsmart.tom.util
Class TOMUtil
- java.lang.Object
-
- bftsmart.tom.util.TOMUtil
-
public class TOMUtil extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static int
RR_DELIVERED
static int
RR_REPLY
static int
RR_REQUEST
static int
SM_ASK_INITIAL
static int
SM_REPLY
static int
SM_REPLY_INITIAL
static int
SM_REQUEST
static int
STOP
static int
STOPDATA
static int
SYNC
static int
TRIGGER_LC_LOCALLY
static int
TRIGGER_SM_LOCALLY
-
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 messagesstatic 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.
-
-
-
Field Detail
-
RR_REQUEST
public static final int RR_REQUEST
- See Also:
- Constant Field Values
-
RR_REPLY
public static final int RR_REPLY
- See Also:
- Constant Field Values
-
RR_DELIVERED
public static final int RR_DELIVERED
- See Also:
- Constant Field Values
-
STOP
public static final int STOP
- See Also:
- Constant Field Values
-
STOPDATA
public static final int STOPDATA
- See Also:
- Constant Field Values
-
SYNC
public static final int SYNC
- See Also:
- Constant Field Values
-
SM_REQUEST
public static final int SM_REQUEST
- See Also:
- Constant Field Values
-
SM_REPLY
public static final int SM_REPLY
- See Also:
- Constant Field Values
-
SM_ASK_INITIAL
public static final int SM_ASK_INITIAL
- See Also:
- Constant Field Values
-
SM_REPLY_INITIAL
public static final int SM_REPLY_INITIAL
- See Also:
- Constant Field Values
-
TRIGGER_LC_LOCALLY
public static final int TRIGGER_LC_LOCALLY
- See Also:
- Constant Field Values
-
TRIGGER_SM_LOCALLY
public static final int TRIGGER_SM_LOCALLY
- See Also:
- Constant Field Values
-
-
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 signaturemessage
- 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 signaturemessage
- the signed messagesignature
- 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 verificationmessage
- the signed messagesignature
- 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)
-
-