Skip to content

Commit

Permalink
ZCS-13176: updating the code
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamCS03 committed Jan 2, 2025
1 parent f8a990a commit fe7c3fb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion store/src/java/com/zimbra/cs/service/util/SecretKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class SecretKey {
public static final int KEY_SIZE_BYTES = 32;
public static final String MSGVRFY_HEADER_PREFIX = "hash=SHA256;guid=";
public static final String MSGVRFY_ALGORITHM_NAME = "SHA-256";
public static final String HEX_64_ZERO_PADDED_FORMAT = "%064x";

/**
* returns the randomly generated String
Expand Down Expand Up @@ -86,7 +87,9 @@ private static String getHashForMessageVerification(String input) throws Service
try {
MessageDigest md = MessageDigest.getInstance(MSGVRFY_ALGORITHM_NAME);
byte[] messageDigest = md.digest(input.getBytes(StandardCharsets.UTF_8));
return Base64.getEncoder().encodeToString(messageDigest);
BigInteger number = new BigInteger(1, messageDigest);
String hexString = String.format(HEX_64_ZERO_PADDED_FORMAT, number);
return Base64.getEncoder().encodeToString(hexString.getBytes());
} catch (NoSuchAlgorithmException e) {
throw ServiceException.FAILURE("Unable to encrypt", e);
}
Expand Down

0 comments on commit fe7c3fb

Please sign in to comment.