MD5 encryption in Oracle and OracleMD5 Encryption

Source: Internet
Author: User

MD5 encryption in Oracle and OracleMD5 Encryption

I. Technical Points

1. DBMS_OBFUSCATION_TOOLKIT.MD5
DBMS_OBFUSCATION_TOOLKIT.MD5 is an MD5-encoded data packet function, but an error message is displayed when select DBMS_OBFUSCATION_TOOLKIT.MD5 (input_string => 'abc') a from Dual, it seems that this function can only be called directly in the package and cannot be directly applied to SELECT statements.
  
2. Utl_Raw.Cast_To_Raw
The string returned by DBMS_OBFUSCATION_TOOLKIT.MD5 is of the RAW type. to display the string correctly, it must undergo Utl_Raw.Cast_To_Raw conversion.

II. Application

1. Direct call

Copy codeThe Code is as follows:
Declare
V2 varchar2 (32); begin
V2: = Utl_Raw.Cast_To_Raw (sys. dbms_obfuscation_toolkit.md5 (input_string => '2016 '));
Dbms_output.put_line (v2); end;

Note: It can be called directly in the stored procedure. If you want to nest the md5 call, remember to use Utl_Raw.Cast_To_Raw for conversion after each call. Otherwise, the final result is incorrect.

2. Call the constructor

Copy codeThe Code is 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;

Example of calling the md5 function:

Copy codeThe Code is as follows:
Select md5 (1) from dual

Appendix: MD5 function statements in Oracle

Copy codeThe Code is as follows:
-- MD5 function statement 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;


How to change the password field in the oracle database to MD5 encryption?

UPDATE table SET password = MD5 (password );
I don't know if there is any in oracle, but mysql does.

Oracle MD5 encryption and java program processing steps

1: Create an md5-encrypted function in oracle. The code can be found below:

Create or replace function MD5 (vin_string IN VARCHAR2)
RETURN VARCHAR2 IS
BEGIN
Return upper (Dbms_Obfuscation_Toolkit.Md5 (input => utl_raw.cast_to_raw (vin_string )));
END MD5

2: The passwords are stored in the database using the ciphertext stored in md5, and the matching results are consistent in the ciphertext. No decryption is required. If decryption is performed, the user is not satisfied.

Related Article

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.