MD5 Encryption in Oracle

Source: Internet
Author: User
Tags md5 encryption

Iamlaosong

Because of the use of MD5 encryption, so on the Internet to search the relevant information, and conduct a careful study. The core is the MD5 encoded packet function:dbms_obfuscation_toolkit. MD5, where the raw type is concerned, is actually the original code value.

The result of MD5 encryption is a 16 byte value, which is is the Raw type, is not displayed, to correctly display, need to undergo utl_raw.cast_to_raw conversion, the function is to each byte of the ASCII value is expressed in characters. To illustrate this, consider the following: Assuming that the binary value of a byte is 0100 0001, the hexadecimal representation is 41, and the value is actually the ASCII code value of the letter "A", then it becomes the string "41" after the Utl_raw.cast_to_raw conversion.

The Utl_raw.cast_to_raw function can also convert a string, that is, the code value of the string (which should be an Oracle character set) in hexadecimal notation, for example:

The result of Utl_raw.cast_to_raw (' Iamlaosong ') is: 69616d6c616f736f6e67

The result of Utl_raw.cast_to_raw (' I'm Lao Song ') is: CED2CAC7C0CFCBCE


The MD5 package functions are used as follows:

1 , call directly

Declare

V2 VARCHAR2 (32);

Begin

V2: = Utl_raw.cast_to_raw (sys.dbms_obfuscation_toolkit.md5 (input_string = ' 123456 '));

Dbms_output.put_line (v2);

End

displaying results: e10adc3949ba59abbe56e057f20f883e

This string is actually the result of a 16-byte value in hexadecimal, where the characters are 0-9 and A-f, and because of this, the letter case is irrelevant, all representing the same value.

For example, the string: Iamlaosong, the result of the encrypted display: 7e0fb497d8c4515157ddeafc2e511290, apparently, is also a hexadecimal representation of 16 bytes.

As for the comparison of encryption results, it is more intuitive to convert to string, and it is easier to compare them.


2 , constructor, and then call the

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:

Select MD5 (1) from dual



MD5 Encryption in Oracle

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.