w2b
w2b

Reputation: 41

Generate hash value of rsa public key

I need to generate hash value(sha256) of rsa public key for purpose of ebics comunications. I've aready tried two solutions: phpSecLib and linux command openssl(public.pem file i generate with help of phpSecLib - i think public.pem is ok cause i've try to convert modulus and exponent to pem with my key):

openssl pkey -in public.pem -pubin -pubout -outform DER | openssl dgst -sha256 -c

None of above gives me proper result. How do i now its not good. Bank sends me modulus and exponent of theirs public keys and corresponding hash values. I've also tried with keys placed in ebics documentation but also without any success.

Bank key modulus: 00f9d48dcb1a7d0cf09350c12fbc41fd1b212d1a49057bcbb404d1386da09d3ee1f1e25246608da8a826ad8f05bfdad6d447a471cefadd7202a01e5b6a1c7f4e93891d8d172a35c8667034a4dde709a3fca3070fc652ce97771778331e12e2d69ab406293cceb936d1d4bf41849b124d8739a37bfce039a833012f4795252161557b6e684ea377771f6c1c226a82772813819702756b0cea162c1c8a04105cc34018ca96fc025723d941752450643ae7f1452483f248907bc937a078f61377c7baf62f21fa368c5a9c45e69adc246a8ad0d2b880ccc4d7591d3b95f5f9f12c455540728afb9fed2276b2a1cffbe11c6af61bf494586c0b93f3ca1c235166de6c6d

Bank key exponent: 010001

Proper hash value:

18 72 B2 39 FF 1C 68 5E 68 D8 DE D8 08 19 C0 4F 52 D8 70 E8 73 E7 56 89 99 99 4E 8C 23 45 32 1C

Upvotes: 1

Views: 2788

Answers (2)

Zuxelus
Zuxelus

Reputation: 11

If you open EBICS specification you will see next description in section 5.5.1.1.1 "The SHA-256 hash values of the financial institution's public keys for X002 and E002 are composed by concatenating the exponent with a blank character and the modulus in hexadecimal representation (using lower case letters) without leading zero (as to the hexadecimal representation). The resulting string has to be converted into a byte array based on US ASCII code."

So you can just open any online sha256 generator and put "10001 f9d48dc...e6c6d" and get your proper hash "1872..321C"

Upvotes: 1

w2b
w2b

Reputation: 41

It looks like there is no standard. For different key formats it would be different hash. In my case(for ebics purpose) its sha256(ltrim($exponent, 0) . ' ' . $modulus);

Upvotes: 0

Related Questions