We have an interface with a company that is request we send them a SHA-1 hash to validate the request being sent to them. I have found that in certain cases the hash being returned is not the expected result.
In the test case of hashing the value Y8xBv4vS3330034646474832741000000008995840 the program below that we have using Qc3CalculateHash returns the value as WC2JQXZbDvrs/skvss+/2+LtOA==.
The vendor we are working with stated that this value is incorrect and they were expecting WC2JQXZbDvrs/skvss+/2+LtOEA=. So we created a php program to return the SHA-1 hash of this program and we did receive the same results as what the vendor expected.
Now most of the time with other values to hash Qc3CalculateHash will return the expected results but occasionally it does not. Below is the code that we are using to produce the SHA-1 hash. This is running on a machine with V7r1 installed.
And here is the php program to hash the value
If anyone has any suggestions as to what could be causing this issue it would be greatly appreciated.
Thank you
Bob
In the test case of hashing the value Y8xBv4vS3330034646474832741000000008995840 the program below that we have using Qc3CalculateHash returns the value as WC2JQXZbDvrs/skvss+/2+LtOA==.
The vendor we are working with stated that this value is incorrect and they were expecting WC2JQXZbDvrs/skvss+/2+LtOEA=. So we created a php program to return the SHA-1 hash of this program and we did receive the same results as what the vendor expected.
Now most of the time with other values to hash Qc3CalculateHash will return the expected results but occasionally it does not. Below is the code that we are using to produce the SHA-1 hash. This is running on a machine with V7r1 installed.
Code:
h DFTACTGRP(*NO) ACTGRP('AS') BNDDIR('COMBASE64') debug /copy *libl/qprotosrc,BASE64_H d Qc3CalculateHash... d PR ExtProc('Qc3CalculateHash') d InData * value d IndataL 10i 0 const d InDataF 8a const d AlgoDes 16a const d AlgoFmt 8a const d CryptoSP 1a const d CryptoDev 1a const options(*omit) d Hash 64a options(*varsize:*omit) d ErrorCode 32767a options(*varsize) d ALGD0500_t ds qualified d based(Template) d HashAlg 10i 0 d QDCXLATE PR ExtPgm('QDCXLATE') d len 5p 0 const d data 32702a options(*varsize) d table 10a const d cvthc PR ExtProc('cvthc') d target 65534A options(*varsize) d src_bits 32767A options(*varsize) const d tgt_length 10I 0 value d ErrorNull ds qualified d BytesPro 10i 0 inz(0) d BytesAvai 10i 0 inz(0) d HASH_MD5 c 1 d HASH_SHA1 c 2 d HASH_SHA256 c 3 d HASH_SHA384 c 4 d HASH_SHA512 c 5 d data s 2000A d len s 10i 0 d alg ds likeds(ALGD0500_t) d bin s 20a d $hex s 40a ***************************** C *entry plist C parm InValue 47 C parm OutValue 28 /free data = InValue; len = %len(%trimr(data)); alg.HashAlg = HASH_SHA1; //Set the HASH Algorithm you want to use ! //Convert from EBCDIC to ASCII (skip this step if you want Hash in EBCDIC) QDCXLATE(len: data: 'QTCPASC'); //API to calculate the SHA1 hash Qc3CalculateHash( %addr(data) : len : 'DATA0100' : alg : 'ALGD0500' : '0' : *OMIT : bin : ErrorNull ); base64_encode( %addr(bin) : %len(%trimr(bin)) : %addr(OutValue) : %size(OutValue)); dsply OutValue; *inlr = *on; /end-free
PHP Code:
<?php
$stringtohash ='Y8xBv4vS3330034646474832741000000008995840';
$hash = sha1($stringtohash, true);
echo $signature = base64_encode($hash);
?>
Thank you
Bob
Comment