Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to Hash a data inCOBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Log Thangavel

New User


Joined: 19 Jan 2018
Posts: 18
Location: USA

PostPosted: Tue May 07, 2019 8:35 pm    Post subject: How to Hash a data inCOBOL
Reply with quote

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
View user's profile Send private message

enrico-sorichetti

Senior Member


Joined: 14 Mar 2007
Posts: 10631
Location: italy

PostPosted: Tue May 07, 2019 9:01 pm    Post subject: Reply to: How to Hash a data inCOBOL
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8498
Location: Dubuque, Iowa, USA

PostPosted: Tue May 07, 2019 9:24 pm    Post subject: Reply to: How to Hash a data inCOBOL
Reply with quote

You are getting EXACTLY what you are supposed to get. From the manual at https://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
View user's profile Send private message
enrico-sorichetti

Senior Member


Joined: 14 Mar 2007
Posts: 10631
Location: italy

PostPosted: Tue May 07, 2019 9:58 pm    Post subject: Reply to: How to Hash a data inCOBOL
Reply with quote

sorry Robert, please let me disagree
i believe that the proper manual reference is this one

https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.csfb400/owh.htm


Quote:
SHA-256 Hash algorithm is SHA-256 algorithm. Length of hash generated is 32 bytes.




but I wonder why the two manuals report different values icon_eek.gif
Back to top
View user's profile Send private message
Log Thangavel

New User


Joined: 19 Jan 2018
Posts: 18
Location: USA

PostPosted: Tue May 07, 2019 10:17 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Log Thangavel

New User


Joined: 19 Jan 2018
Posts: 18
Location: USA

PostPosted: Tue May 07, 2019 10:30 pm    Post subject: Reply to: How to Hash a data inCOBOL
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Senior Member


Joined: 14 Mar 2007
Posts: 10631
Location: italy

PostPosted: Tue May 07, 2019 10:45 pm    Post subject: Reply to: How to Hash a data inCOBOL
Reply with quote

You show the java hash in hexadecimal ,
do the same for the cobol hash


I wonder, 32 decimal = 20 hexadecimal ...
Back to top
View user's profile Send private message
Log Thangavel

New User


Joined: 19 Jan 2018
Posts: 18
Location: USA

PostPosted: Wed May 08, 2019 6:07 am    Post subject:
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Senior Member


Joined: 14 Mar 2007
Posts: 10631
Location: italy

PostPosted: Sat May 11, 2019 3:23 pm    Post subject: Reply to: How to Hash a data inCOBOL
Reply with quote

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
View user's profile Send private message
Log Thangavel

New User


Joined: 19 Jan 2018
Posts: 18
Location: USA

PostPosted: Thu May 16, 2019 7:32 am    Post subject: thank you
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Senior Member


Joined: 14 Mar 2007
Posts: 10631
Location: italy

PostPosted: Thu May 16, 2019 11:20 am    Post subject: Reply to: How to Hash a data inCOBOL
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Extract data from n DB2 Views automat... esmeraldo All Other Mainframe Topics 4 Wed Nov 13, 2019 12:32 am
No new posts adrdssu for copy all data robyjhl JCL & VSAM 5 Tue Nov 12, 2019 11:17 pm
No new posts Convert mainframe data to .csv format... karan_reddy DFSORT/ICETOOL 10 Sat Nov 02, 2019 2:09 am
No new posts How to place name of the file where t... danielgp89 SYNCSORT 18 Thu Oct 17, 2019 12:55 am
No new posts How to force ISPF to allocate ISPF te... Michele Giannuli TSO/ISPF 9 Thu Sep 12, 2019 2:03 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us