Skip to content

Instantly share code, notes, and snippets.

@RevenueGitHubAdmin
Created June 14, 2018 16:13
Show Gist options
  • Save RevenueGitHubAdmin/17073ac5724d19c69d950b76f41fa0fa to your computer and use it in GitHub Desktop.
Save RevenueGitHubAdmin/17073ac5724d19c69d950b76f41fa0fa to your computer and use it in GitHub Desktop.
[JavaScript] How to encode the password to open the keystore.
/*
* The following snippet uses the Forge JavaScript library (https://github.com/digitalbazaar/forge)
* to generate 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. For more information about how to use the Forge JavaScript library, please, refer to
* the aforementioned URL.
*
* 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.
*/
function encodePassword(plainTextPassword) {
var passwordMD5Hash = forge.md.md5
.create()
.update(plainTextPassword)
.digest()
.getBytes();
return forge.util.encode64(passwordMD5Hash);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment