View previous topic :: View next topic
|
Author |
Message |
Log Thangavel
New User
Joined: 19 Jan 2018 Posts: 18 Location: USA
|
|
|
|
Hi,
I need to hash a data (19 bytes) to 32 Bytes ysing SHA-256 algorithm. We basically need to match an hash values generated by other application.
I tried to hash using CSNBOWH program but the output of hash is only 20 bytes. Also the output hash value doesn't match with the hash value produced in Java. Cobol produces hash like 0V2!6... so on whereas in java its like 34349sd203a23232...
Pls advise if we have any other function to hash it |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
there is no reason for CSNBOWH not to work
unfortunately the information You posted is pretty useless
You only told that something does not provide the expected results |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
You are getting EXACTLY what you are supposed to get. From the manual at www.ibm.com/support/knowledgecenter/en/linuxonibm/com.ibm.linux.z.wskc.doc/wskc_r_owhparameters.html on CSNBOWH (emphasis added by me):
Quote: |
rule_array
Direction: Input
Type: String array
These keywords provide control information to the verb. The optional chaining flag keyword indicates whether calls to this verb are chained together logically to overcome buffer size limitations. Each keyword is left-aligned in an 8-byte field and padded on the right with blanks. All keywords must be in contiguous storage. The rule_array keywords are described in Table 1.
Table 1. Keywords for One-Way Hash control informationKeyword Description
Hash method (One, required). The SHA-based hashing functions use CPACF by default. For details about CPACF, see CPACF support.
MD5 Hash algorithm is MD5 algorithm. Use this hash method for PKCS-1.0 and PKCS-1.1. Length of hash generated is 16 bytes.
RPMD-160 Hash algorithm is RIPEMD-160. Length of hash generated is 20 bytes.
SHA-1 Hash algorithm is SHA-1 algorithm. Length of hash generated is 20 bytes.
SHA-224 Hash algorithm is SHA-224 algorithm. Length of hash generated is 20 bytes.
SHA-256 Hash algorithm is SHA-256 algorithm. Length of hash generated is 20 bytes.
SHA-384 Hash algorithm is SHA-384 algorithm. Length of hash generated is 20 bytes.
SHA-512 Hash algorithm is SHA-512 algorithm. Length of hash generated is 20 bytes. |
Why do you think you should get a 32-byte output hash? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
Back to top |
|
|
Log Thangavel
New User
Joined: 19 Jan 2018 Posts: 18 Location: USA
|
|
|
|
Thanks Robert & Enrico for the response. I was about to ping the same link where it says it would convert 32 bytes. My concern was the hash value converted in Java & COBOL was different.
My requirement is we have to compare the hashed values sent from Java application & COBOL.
So in this process the hashed values produced by Java is different from the one this CSNBOWH utility had produced. I will share the sample in fewm ins |
|
Back to top |
|
|
Log Thangavel
New User
Joined: 19 Jan 2018 Posts: 18 Location: USA
|
|
|
|
For value 567
Java o/p 97a6d21df7c51e8289ac1a8c026aaac143e15aa1957f54f42e30d8f8a85c3a55
Cobol o/p
ep[yif.e$1?... (32 bytes) couldn’t find few chars on this keyboard |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
You show the java hash in hexadecimal ,
do the same for the cobol hash
I wonder, 32 decimal = 20 hexadecimal ... |
|
Back to top |
|
|
Log Thangavel
New User
Joined: 19 Jan 2018 Posts: 18 Location: USA
|
|
|
|
Thanks for your response.
Guess the value after hashed is stored in EBCDIC which is 32 bytes and if we convert to hex it would become 64. But I mapped with copybook to lookup as hex value. The hex values doesn’t match with the hex value generated by java code. Even it used same sha-256 algorithm |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
For value 567
Java o/p 97a6d21df7c51e8289ac1a8c026aaac143e15aa1957f54f42e30d8f8a85c3a55
|
unfortunately You are comparing apples to chairs
what You posted is the sha256 hash computed on a PC
567 = x'353637'
the sha256 hash for 567 on the mainframe
567 = x'f5f6f7'
is
Code: |
AB16DB3E09771F115A01ED373FA2E2605447033DA1DD89403A437A367BEAC255 |
to double check I run my test
on 567
and x'353637'
on my mac
and the result in both cases was , guess what ...
Code: |
97A6D21DF7C51E8289AC1A8C026AAAC143E15AA1957F54F42E30D8F8A85C3A55
97A6D21DF7C51E8289AC1A8C026AAAC143E15AA1957F54F42E30D8F8A85C3A55
|
|
|
Back to top |
|
|
Log Thangavel
New User
Joined: 19 Jan 2018 Posts: 18 Location: USA
|
|
|
|
So the results were same.
Actually It worked when I converted the string to Ascii format and then passed that value to CSNBOWH which yields this results but in X'97A6D'....
Can you please tell me what was the format of the input field. When I had the field as say
Var1 PIC X(19).. It produced different results not the actual hash value |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
unfortunately your last post was clear as mud ...
the hash algorithm is pretty agnostic ....
the PIC is irrelevant
what counts is the length You provide
actually until now You did not post anything useful,
You jjust whined that something did not work to your expectations
post the call
and the content of the variables used ( in Hex )
and ... USE THE CODE TAGS |
|
Back to top |
|
|
|