Hash created using DBMS_CRYPTO.Hash and md5sum, sha1sum not maching.
253908Apr 27 2009 — edited Oct 14 2009Hi,
I have PL/SQL script MD5SH1.sql to generate md5 and sha1 hash, but hash generated by this script and
hash generated by md5sum and sha1sum utility not matching.
Pl. tell me what is wrong,
------------------MD5SH1.sql----------------
set serveroutput on
DECLARE
input_string VARCHAR2 (200) := 'Lord of the ring'';
output_str_md5 VARCHAR2 (200);
output_str_sh1 VARCHAR2 (200);
hash_raw_md5 RAW(2000);
hash_raw_sh1 RAW(2000);
hash_algo_type1 PLS_INTEGER := DBMS_CRYPTO.HASH_MD5;
hash_algo_type2 PLS_INTEGER := DBMS_CRYPTO.HASH_SH1;
BEGIN
DBMS_OUTPUT.PUT_LINE ( 'Original string: ' || input_string);
hash_raw_md5 := DBMS_CRYPTO.Hash
(
src => UTL_I18N.STRING_TO_RAW (input_string, NULL),
--src => input_string,
typ => hash_algo_type1
);
hash_raw_sh1 := DBMS_CRYPTO.Hash
(
src => UTL_I18N.STRING_TO_RAW (input_string, NULL),
--src => input_string,
typ => hash_algo_type2
);
output_str_md5 := UTL_I18N.RAW_TO_CHAR (hash_raw_md5,'US7ASCII');
output_str_sh1 := UTL_I18N.RAW_TO_CHAR (hash_raw_sh1,'US7ASCII');
--output_str_md5 := hash_raw_md5;
--output_str_sh1 := hash_raw_sh1;
--dbms_output.put_line(hash_raw_md5);
--dbms_output.put_line(rawtohex(hash_raw_sh1));
DBMS_OUTPUT.PUT_LINE ('MD5 Hash: ' || output_str_md5);
DBMS_OUTPUT.PUT_LINE ('SH1 Hash: ' || output_str_sh1);
END;
/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The O/p of this script is
SYS@mydb> @MD5SH1.sql
Original string: Lord of the ring
MD5 Hash: �����+.v�`�a_A
SH1 Hash:
����E�k�[�F[c�2�
PL/SQL procedure successfully completed.
SYS@mydb>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The o/p of md5sum and sha1sum is
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[san@sde4 ~]$ echo "Lord of the ring" |md5sum
f3fbb6dfd8a2d6f8f6aeabc4d6e17c57 -
[san@sde4 ~]$ echo "Lord of the ring" |sha1sum
856f6132e23c7e335ca4188bd45c7bc9515f6905 -
[san@sde4 ~]$
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Why these 2 hashes are not matching?
-Santosh Mhaskar