SHA 256 value calculation for a file in servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I want to calculate sha 256 value for a file in servicenow the below i got from command prompt teh sha 256 value the same i need to get in servicenow, the value should not change on each run it should be fixed
Algorithm Hash Path
--------- ---- ----
SHA256 BDD1A33DE78618D16EE4CE148B849932C05D0015491C34887846D431D29F308E C:\Users
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11m ago
Yes, you can achieve this in ServiceNow, and the correct approach for your requirement is to use GlideDigest with getSHA256HexFromInputStream.
Since you want the SHA-256 value of a file and it must match what you get from the command prompt, you should hash the raw file content, not a string version of it. The best way to do that is to read the attachment as a content stream and pass it into GlideDigest.
Example:
var inputStream = new GlideSysAttachment().getContentStream(attachmentSysID);
var digest = new GlideDigest();
var hash = digest.getSHA256HexFromInputStream(inputStream);
gs.info(hash);This method generates the SHA 256 hash in hexadecimal format and will produce the same fixed value every time for the same file, just like the OS level SHA 256 calculation.
Official Documentation: GlideDigest | ServiceNow Developers

