- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Hash created using DBMS_CRYPTO.Hash and md5sum, sh...
Operating System - HP-UX
1819928
Members
3031
Online
109607
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2009 03:24 AM
тАО07-23-2009 03:24 AM
Hash created using DBMS_CRYPTO.Hash and md5sum, sha1sum not maching
Hi,
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?
=============================================
-------OR It can be put like this -----------
=============================================
a] md5 hash generated by DBMS_CRYPTO.Hash function
SYS@mydb> @MD5SH1.sql
Original string: Lord of the ring
MD5 Hash: я┐╜я┐╜я┐╜я┐╜я┐╜+.vя┐╜`я┐╜a_A
is not matching with the hash generated by md5sum utility.
san@sde4 ~$ echo "Lord of the ring" |md5sum
f3fbb6dfd8a2d6f8f6aeabc4d6e17c57 -
and
b] sha1 hash generated by DBMS_CRYPTO.Hash function
SYS@mydb> @MD5SH1.sql
Original string: Lord of the ring
MD5 Hash: я┐╜я┐╜я┐╜я┐╜я┐╜+.vя┐╜`я┐╜a_A
*SH1 Hash:
я┐╜я┐╜ я┐╜я┐╜Eя┐╜k я┐╜[я┐╜F[c я┐╜2я┐╜*
is not matching with the hash generated by sha1sum utility.
san@sde4 ~$ echo "Lord of the ring" |sha1sum
856f6132e23c7e335ca4188bd45c7bc9515f6905 -
why is this mismatch if hash value is expected to be same for same algorithm.
-Santosh Mhaskar
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?
=============================================
-------OR It can be put like this -----------
=============================================
a] md5 hash generated by DBMS_CRYPTO.Hash function
SYS@mydb> @MD5SH1.sql
Original string: Lord of the ring
MD5 Hash: я┐╜я┐╜я┐╜я┐╜я┐╜+.vя┐╜`я┐╜a_A
is not matching with the hash generated by md5sum utility.
san@sde4 ~$ echo "Lord of the ring" |md5sum
f3fbb6dfd8a2d6f8f6aeabc4d6e17c57 -
and
b] sha1 hash generated by DBMS_CRYPTO.Hash function
SYS@mydb> @MD5SH1.sql
Original string: Lord of the ring
MD5 Hash: я┐╜я┐╜я┐╜я┐╜я┐╜+.vя┐╜`я┐╜a_A
*SH1 Hash:
я┐╜я┐╜ я┐╜я┐╜Eя┐╜k я┐╜[я┐╜F[c я┐╜2я┐╜*
is not matching with the hash generated by sha1sum utility.
san@sde4 ~$ echo "Lord of the ring" |sha1sum
856f6132e23c7e335ca4188bd45c7bc9515f6905 -
why is this mismatch if hash value is expected to be same for same algorithm.
-Santosh Mhaskar
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-28-2009 12:08 AM
тАО07-28-2009 12:08 AM
Re: Hash created using DBMS_CRYPTO.Hash and md5sum, sha1sum not maching
The output of the hash function is a long string of bits. If you wish to display it like md1sum or sha1sum do, you must convert it to a hexadecimal form first.
If you just convert it to raw ASCII characters, you will get control characters and other random, maybe un-displayable nonsense that can confuse your display.
The commented-out line:
"--dbms_output.put_line(rawtohex(hash_raw_sh1));"
would have the right idea. I don't know enough PL/SQL to know offhand if the syntax of rawtohex() is correct or not.
MK
If you just convert it to raw ASCII characters, you will get control characters and other random, maybe un-displayable nonsense that can confuse your display.
The commented-out line:
"--dbms_output.put_line(rawtohex(hash_raw_sh1));"
would have the right idea. I don't know enough PL/SQL to know offhand if the syntax of rawtohex() is correct or not.
MK
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-28-2009 12:52 AM
тАО07-28-2009 12:52 AM
Re: Hash created using DBMS_CRYPTO.Hash and md5sum, sha1sum not maching
Thanks Matti,
I'll convert it to hexadecimal and then see.
-Santosh
I'll convert it to hexadecimal and then see.
-Santosh
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP