MD5 encryption in Oracle
Because MD5 encryption is used, I searched the internet for relevant information and studied it carefully. Its core is the MD5-encoded data packet function: DBMS_OBFUSCATION_TOOLKIT.MD5, which involves the RAW type, which is actually the original code value.
The MD5 encryption result is 16 byte values, that is, RAW type, which cannot be displayed. to display the values correctly, it must undergo Utl_Raw.Cast_To_Raw conversion, this function represents the value of each byte in hexadecimal notation. For clarity, for example: assume that the binary value of A byte is 0100 0001, And the hexadecimal value is 41 (this value is actually the ASCII code value of the letter "A", which is hard to be displayed, it can still be displayed as A, but some non-ASCII code values cannot be displayed, such as 1100 0001, Which is C1 in hexadecimal format ), after Utl_Raw.Cast_To_Raw conversion, it becomes the string "41 ".
The Utl_Raw.Cast_To_Raw function can also convert a string, that is, the code value of the string (which should be the internal code of the Oracle Character Set) is expressed in hexadecimal format. For example:
Utl_raw.cast_to_raw ('iamlaosong'): 69616D6C616F736F6E67
Utl_raw.cast_to_raw ('I am lause'): CED2CAC7C0CFCBCE
The MD5 Package function is used as follows:
1. Direct call
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;
Result: E10ADC3949BA59ABBE56E057F20F883E
This string is actually the result of a 16-byte value in hexadecimal notation, where the characters are 0-9 and A-F, because of this, where the letter is case-insensitive, indicates the same value.
Another example is the string iamlaosong. The encrypted result is 7e0fb497d8c4515157ddeafc2e0000290. Obviously, it is also a hexadecimal representation of 16 bytes.
As for the comparison of the encryption results, it is more intuitive and convenient to convert them into strings.
2. Call the constructor
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