MD5 Encryption in Oracle _oracle

Source: Internet
Author: User

First, technical points

1, Dbms_obfuscation_toolkit. MD5
Dbms_obfuscation_toolkit. MD5 is a MD5 encoded packet function, but I am using select Dbms_obfuscation_toolkit. MD5 (input_string => ' abc ') A from dual, it appears that the function can only be invoked directly in the package and cannot be applied directly to the SELECT statement.
  
2, Utl_raw.cast_to_raw
Dbms_obfuscation_toolkit. MD5 returns the string, is the Raw type, to be properly displayed, requires a utl_raw.cast_to_raw conversion

Second, the application

1. Direct call

Copy Code code as follows:

Declare
V2 VARCHAR2 (32); Begin
V2: = Utl_raw.cast_to_raw (sys.dbms_obfuscation_toolkit.md5 (input_string => ' 111 '));
Dbms_output.put_line (v2); End

Note: You can call directly in the stored procedure, if you want to nest call MD5, remember to use Utl_raw.cast_to_raw after each call, or the final result is wrong.

2, after the constructor, and then call

Copy Code code as follows:

CREATE OR REPLACE FUNCTION MD5 (
passwd in VARCHAR2) return VARCHAR2 is
retval Varchar2 (32); BEGIN
retval: = Utl_raw.cast_to_raw (Dbms_obfuscation_toolkit. MD5 (input_string => passwd)); return retval; End;

Call the MD5 function example:

Copy Code code as follows:

Select MD5 (1) from dual

Additional: Oracle MD5 Function statement

Copy Code code as follows:

MD5 function statements in--oracle
Create or replace FUNCTION "Md5hash" (str in VARCHAR2)
Return VARCHAR2
Is V_checksum VARCHAR2 (32);

BEGIN
V_checksum: = LOWER (Rawtohex (Utl_raw. Cast_to_raw (SYS.DBMS_OBFUSCATION_TOOLKIT.MD5 (input_string => str)));
return v_checksum;
EXCEPTION
When No_data_found THEN
NULL;
When others THEN
--Consider logging the error and then re-raise raise;
End Md5hash;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.