Skip to content

Instantly share code, notes, and snippets.

@RevenueGitHubAdmin
Created June 14, 2018 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RevenueGitHubAdmin/d8a0275dea117848581b0e50ab57327a to your computer and use it in GitHub Desktop.
Save RevenueGitHubAdmin/d8a0275dea117848581b0e50ab57327a to your computer and use it in GitHub Desktop.
[Java] How to encode the password to open the keystore.
/*
* The following snippet generates the MD5 hash of a plain text String and encode the result
* into a BASE64 String. This snippet exemplify how to proper encode the keystore password
* before use it to access the certificate and keys.
*
* Gists provided for illustrative purposes only. Developers can use these as a support tool
* but the Office of the Revenue Commissioners (Revenue) does not provide any warranty with
* these gists.
*/
public String encodePassword(String plainTextPassword) throws NoSuchAlgorithmException {
MessageDigest md5Digest = MessageDigest.getInstance("MD5");
byte[] passwordHash = md5Digest.digest(
plainTextPassword.getBytes(StandardCharsets.UTF_8)
);
return Base64.getEncoder().encodeToString(passwordHash);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment