Package com.easypost.utils
Class Cryptography
java.lang.Object
com.easypost.utils.Cryptography
Class for various cryptography utilities.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnums for the supported HMAC algorithms. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]createHMAC(byte @NotNull [] data, @NotNull String key, @NotNull Cryptography.HmacAlgorithm algorithm) Calculate the HMAC hex digest of a string.static StringhexEncodeToString(byte @NotNull [] bytes) Hex-encode a byte array to a string.static booleansignaturesMatch(byte @NotNull [] signature1, byte @NotNull [] signature2) Check whether two signatures match.static booleansignaturesMatch(@NotNull String signature1, @NotNull String signature2) Check whether two signatures match.static StringtoHMACSHA256HexDigest(byte @NotNull [] data, @NotNull String key, @Nullable Normalizer.Form normalizationForm) Calculate the HMAC-SHA256 hex digest of a string.
-
Constructor Details
-
Cryptography
public Cryptography()
-
-
Method Details
-
hexEncodeToString
Hex-encode a byte array to a string.- Parameters:
bytes- the byte array to hex-encode.- Returns:
- the hex-encoded byte array string.
-
toHMACSHA256HexDigest
public static String toHMACSHA256HexDigest(byte @NotNull [] data, @NotNull @NotNull String key, @Nullable Normalizer.Form normalizationForm) Calculate the HMAC-SHA256 hex digest of a string.- Parameters:
data- Data to calculate hex digest for.key- Key to use in HMAC calculation.normalizationForm-Normalizer.Formto use when normalizing key. No normalization when null.- Returns:
- Hex digest of data.
-
createHMAC
public static byte[] createHMAC(byte @NotNull [] data, @NotNull @NotNull String key, @NotNull @NotNull Cryptography.HmacAlgorithm algorithm) Calculate the HMAC hex digest of a string.- Parameters:
data- Data to calculate hex digest for.key- Key to use in HMAC calculation.algorithm-Cryptography.HmacAlgorithmto use to calculate HMAC.- Returns:
- Hex digest of data.
-
signaturesMatch
public static boolean signaturesMatch(byte @NotNull [] signature1, byte @NotNull [] signature2) Check whether two signatures match. This is safe against timing attacks.- Parameters:
signature1- First signature to check.signature2- Second signature to check.- Returns:
- True if signatures match, false otherwise.
-
signaturesMatch
public static boolean signaturesMatch(@NotNull @NotNull String signature1, @NotNull @NotNull String signature2) Check whether two signatures match. This is safe against timing attacks.- Parameters:
signature1- First signature to check.signature2- Second signature to check.- Returns:
- True if signatures match, false otherwise.
-