generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change generic to object parameter and make HashHelper a singleton class
- Loading branch information
1 parent
1944f11
commit 36cbaa4
Showing
7 changed files
with
18 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 8 additions & 6 deletions
14
etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/utils/security/HashHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
package gov.hhs.cdc.trustedintermediary.etor.utils.security; | ||
|
||
import gov.hhs.cdc.trustedintermediary.wrappers.Logger; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.HexFormat; | ||
import javax.inject.Inject; | ||
|
||
public class HashHelper implements SecureHash { | ||
@Inject Logger logger; | ||
|
||
private static final HashHelper INSTANCE = new HashHelper(); | ||
|
||
public static HashHelper getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public <T> String generateHash(T input) { | ||
public String generateHash(Object input) { | ||
try { | ||
MessageDigest digest = MessageDigest.getInstance("SHA3-512"); | ||
byte[] objBytes = input.toString().getBytes(StandardCharsets.UTF_8); | ||
byte[] hashBytes = digest.digest(objBytes); | ||
return HexFormat.of().formatHex(hashBytes); | ||
} catch (NoSuchAlgorithmException e) { | ||
logger.logError("Algorithm does not exist!", e); | ||
throw new RuntimeException(e); | ||
throw new RuntimeException("Algorithm does not exist!", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters