Oracle defines the DES encryption and decryption and MD5 encryption function example, des encryption and decryption

Source: Internet
Author: User

Oracle defines the DES encryption and decryption and MD5 encryption function example, des encryption and decryption

(1) DES encryption function

create or replace function
encrypt_des(p_text varchar2, p_key varchar2) return varchar2 is
v_text varchar2(4000);
v_enc varchar2(4000);
raw_input RAW(128) ;
key_input RAW(128) ;
decrypted_raw RAW(2048);
begin
v_text := rpad( p_text, (trunc(length(p_text)/8)+1)*8, chr(0));
raw_input := UTL_RAW.CAST_TO_RAW(v_text);
key_input := UTL_RAW.CAST_TO_RAW(p_key);
dbms_obfuscation_toolkit.DESEncrypt(input => raw_input,key => key_input,encrypted_data =>decrypted_raw);
v_enc := rawtohex(decrypted_raw);
dbms_output.put_line(v_enc);
return v_enc;
end;

(2) DES decryption Function

create or replace function decrypt_des(p_text varchar2,p_key varchar2) return varchar2 is
v_text varchar2(2000); 
begin
dbms_obfuscation_toolkit.DESDECRYPT(input_string => UTL_RAW.CAST_TO_varchar2(p_text),key_string =>p_key, decrypted_string=> v_text);
v_text := rtrim(v_text,chr(0));
dbms_output.put_line(v_text);
return v_text;
end;

(3) MD5 encryption function

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;

(4) function example

DES encryption: update tb_salarysign_staff s set s. staffpwd = encrypt_des (s. staffpwd, 'test #5 & 124 *! De ');

DES decryption: select decrypt_des (s. staffpwd, 'test #5 & 124 *! De ') from tb_salarysign_staff s

MD5 encryption: update tb_salarysign_staff s set s. staffpwd = md5 (s. staffpwd );


MD5 encryption problems?

The so-called MD5, that is, "Message-Digest Algorithm 5 (Information-Digest Algorithm)", is a one-way function Algorithm developed from MD2, MD3, and MD4 (that is, the HASH Algorithm ), it is the first designer of RSA, an internationally renowned public key encryption algorithm standard. rivest was developed in the early 1990s S. The biggest function of MD5 is to "compress" large-capacity file information in different formats before signing private keys with digital signature software into a confidential format, the key is that this "compression" is irreversible.

In order to give readers an intuitive understanding of the MD5 application, I will briefly describe the working process with an example:

Everyone knows that anyone on the Earth has his own unique fingerprint, which is often the most trustworthy way for public security organs to identify criminals. Similarly, MD5 can generate a unique "digital fingerprint" for any file regardless of its size, format, and quantity. If anyone makes any changes to the file, the MD5 value, that is, the corresponding "digital fingerprint", will change.

We often see the MD5 value in a software information on some software download sites. Its function is that after we download the software, use special software (such as Windows MD5 Check) for MD5 verification on the downloaded files to ensure that the files we obtain are the same as the files provided by the site. The MD5 algorithm is widely used in software download sites, Forum databases, and system file security.

The example mentioned above is only a basic application of MD5. In fact, MD5 is also used for encryption and decryption technology, such as Unix and various BSD system logon passwords (DES encryption algorithm was used before the birth of MD5, and DES was eliminated due to higher MD5 Security), Communication Information Encryption (such as the familiar Instant Messaging Software MyIM), digital signatures and many other aspects.

2] I have seen C #, Java, Delphi, and other versions of MD5, which is irreversible encryption, but the encrypted strings generated by the same password are the same

What is MD5 DES encryption?

MD5 encryption program
Package org. lxh. myzngt. util;

Public class MD5Code {
/*
* The following S11-S44 is actually a 4*4 matrix, which is implemented with # define in the original C implementation. Here they are implemented as static
* Final indicates read-only and can be shared among multiple instances in the same process space.
*/
Static final int S11 = 7;

Static final int S12 = 12;

Static final int S13 = 17;

Static final int S14 = 22;

Static final int S21 = 5;

Static final int S22 = 9;

Static final int S23 = 14;

Static final int S24 = 20;

Static final int S31 = 4;

Static final int S32 = 11;

Static final int S33 = 16;

Static final int S34 = 23;

Static final int S41 = 6;

Static final int S42 = 10;

Static final int S43 = 15;

Static final int S44 = 21;

Static final byte [] PADDING = {-128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0 };

/*
* The following three members are the three core data used in the MD5 calculation process. They are defined in the MD5_CTX structure in the original C implementation.
*/
Private long [] state = new long [4]; // state (ABCD)

Private long [] count = new long [2]; // number of bits, modulo 2 ^ 64 (lsb

// First)

Private byte [] buffer = new byte [64]; // input buffer

/*
* DigestHexStr is the only public member of MD5 and is the hexadecimal ASCII representation of the latest calculation result.
*/

Public String digestHexStr;

/*
* Digest is the binary representation of the latest calculation result, indicating the MD5 value of bits.
*/
Private byte [] digest = new byte [16];

/*
* GetMD5ofStr is the main public method of MD5-like. The entry parameter is the string you want to perform MD5 conversion.
* The returned result is the transformed result, which is obtained from the public member digestHexStr.
*/
Pub ...... the remaining full text>

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.