GlideDigest not working to calculate MD5Hash

kailashthiyagar
Kilo Guru

Hi all,

I m using GlideDigest to caclulate MD5hash in my scoped application.. i m in Istanbul release. Here is the code which i m using to calculate MD5Hash.. It generates different value for MD5Hash for my file. Please help me to understand what i m doing wrong over here.

var attachmentSysid='';

var ga=new GlideRecord('sys_attachment');

ga.addQuery('table_sys_id',current.sys_id);

ga.query();

while(ga.next()){

attachmentSysid=ga.sys_id;

}

var inputStream = new GlideSysAttachment().getContentStream(attachmentSysid);

var digest = new GlideDigest();

var test=digest.getMD5Base64FromInputStream(inputStream);

gs.addInfoMessage(test);

This is the link i have referred

https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=c_GlideDigestScopedAPI

And earlier i tried with GlideCheckSum but since it needs to be whitelisted in order for it to be used and also it will work only in scoped application, i happened to go with this approach.

sachin.namjoshi sanjivmeher

1 ACCEPTED SOLUTION

Instead of getMD5Base64FromInputStream i used getMD5HexFromInputStream



Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

11 REPLIES 11

SanjivMeher
Kilo Patron
Kilo Patron

Hi Kailash,


Can you add the message marked in bold? Let me know what results you get for both the gs.addInfo




  1. var attachmentSysid='';  
  2. var ga=new GlideRecord('sys_attachment');  
  3. ga.addQuery('table_sys_id',current.sys_id);  
  4. ga.query();  
  5.  
  6. while(ga.next()){  
  7. attachmentSysid=ga.sys_id;  
  8. }  
  9.   gs.addInfoMessage('attachmentSysid is --------------'+attachmentSysid);
  10. var inputStream = new GlideSysAttachment().getContentStream(attachmentSysid);  
  11. var digest = new GlideDigest();  
  12. var test=digest.getMD5Base64FromInputStream(inputStream);  
  13. gs.addInfoMessage(test);  

Please mark this response as correct or helpful if it assisted you with your question.

sanjivmeher


This is what i have observed.



attachmentSysid gives the sys id of the record in the "sys_attachment" table and it has the file which we attached.



I attached the file in one of the online site, it gives me the expected MD5 value. But through this method, i m getting different MD5Hash value..



If you would like to try it in my instance, here is the information




ServiceNow


UserID : admin


Password :



Table : MD5Hash. And you can check the assoiciated BusinessRule for that


sanjivmeher any help?


Hi Kailash,



What is the expected MD5 value and for which file?



Please mark this response as correct or helpful if it assisted you with your question.