I have to functions to generate a hash (sha512) of a random element. The first one is a oracle sql query:
select RAND, DBMS_CRYPTO.HASH(RAND, 6 /*SHA512*/) as sha512 from
(select DBMS_CRYPTO.RANDOMBYTES(5) as RAND from DUAL);
which returns
RAND
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SHA512
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
C1BEC41854
E4BD639D4726D294CB63B6DDC651C6B6F5708ED3FC9B2E08A71DD7D36958B7B13BD31ECA28039565121F3067167D719292A86B6CAD052EFC9A56923594946084
When I try to generate the hash for C1BEC41854 in python I use the following script
from hashlib import sha512
h = 'C1BEC41854'
b = bytes.fromhex(h)
print(sha512(b).hexdigest())
which returns
a63f4d25b5f0fc51fb27ae1e1c5f4ff19edc7b790d2373071ae8f454e63766a19b69a200690a32a65dd57be5b47fec29ee15c354f52ad5916127bb4cf674ab37
Can you please help me figure out why the both hashes are not identical?
C1BEC41854needs to be converted into bytes before being hashed (it's not magic). Are both methods using the same encoding algorithm? Maybe one has a default UTF-8 encoding and the other one uses ISO-8859-1 or other.hallolike this:select RAND, dbms_crypto.hash(RAND, 6 /*SHA512*/) as sha512 from (select UTL_I18N.STRING_TO_RAW( 'hallo', 'AL32UTF8' ) as RAND from dual);it is working just fine