Created
June 14, 2018 16:11
-
-
Save RevenueGitHubAdmin/22566bb275f5b084d78e3532c0947d3c to your computer and use it in GitHub Desktop.
[JavaScript] How to calculate and encode an element digest.
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
/* | |
* The following snippet uses the Forge JavaScript library (https://github.com/digitalbazaar/forge) | |
* to calculate the SHA512 digest hash of the received element and return it as a BASE64 | |
* encode String. It is used to calculate the digest of the content of the request and it | |
* is an important element of the signature. The expected parameter is the plain text | |
* representation of the request's body being sent. For SOAP, it is the XML node being signed. | |
* For RESTful is the JSON document beingin sent. 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 calculateAndEncodeElementDigest(element) { | |
return forge.util.encode64( | |
forge.md.sha512 | |
.create() | |
.update(element) | |
.digest() | |
.getBytes() | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment