The base and DES encryption methods used in peacetime
For Des plus decryption, the key length is 8 bits, when the number of key bits entered is more than 8 bits automatic interception.
Baotou
Create or Replace package Pkg_compare is
function f_en_base64 (pi_str varchar2) return varchar2;
function f_de_base64 (pi_str varchar2) return varchar2;
Procedure P_decrypt_des
(
Pi_str VARCHAR2
, Pi_key VARCHAR2
, Po_encode out VARCHAR2
);
Procedure P_encrypt_des
(
Pi_str VARCHAR2
, Pi_key VARCHAR2
, Po_encode out VARCHAR2
);
End
Inclusion
Create or Replace package body Pkg_compare is
The/*base64 cryptographic function enters a string that needs to be encrypted, returning the encrypted string. */
function f_en_base64 (pi_str varchar2) return varchar2 is
OUT_BASE64 varchar2 (4000);
Begin
--Call system base64 conversion function
Select Utl_raw.cast_to_varchar2 (Utl_encode.base64_encode (Utl_raw.cast_to_raw (PI_STR)))
Into Out_base64
from dual;
return out_base64;
End
The/*base64 decryption function enters a string that needs to be decrypted, returning the decryption string. */
function f_de_base64 (pi_str varchar2) return varchar2 is
OUT_BASE64 varchar2 (4000);
Begin
--Call system base64 conversion function
Select Utl_raw.cast_to_varchar2 (Utl_encode.base64_decode (Utl_raw.cast_to_raw (PI_STR)))
Into Out_base64
from dual;
return out_base64;
End
/* Solution des stored Procedure */
Procedure P_decrypt_des
(
Pi_str VARCHAR2
, Pi_key VARCHAR2
, Po_encode out VARCHAR2
) is
NV_STR varchar2 (4000);
Begin
--Call des decryption system functions
Dbms_obfuscation_toolkit.desdecrypt (input_string = utl_raw.cast_to_varchar2 (PI_STR)
, key_string = Pi_key
, decrypted_string = NV_STR);
Po_encode: = RTrim (nv_str, Chr (0));
End
/*des Encryption */
Procedure P_encrypt_des
(
Pi_str VARCHAR2
, Pi_key VARCHAR2
, Po_encode out VARCHAR2
) is
NV_STR varchar2 (4000);
Raw_input Raw (128);
Key_input Raw (128);
Decrypted_raw Raw (2048);
Begin
NV_STR: = Rpad (Pi_str, (trunc (Length (PI_STR)/8) + 1) * 8, Chr (0));
Raw_input: = Utl_raw.cast_to_raw (NV_STR);
Key_input: = Utl_raw.cast_to_raw (Pi_key);
Dbms_obfuscation_toolkit.desencrypt (input = Raw_input
, key = Key_input
, encrypted_data = Decrypted_raw);
Po_encode: = Rawtohex (Decrypted_raw);
Return
End
End
Oracle uses Base64 des encryption to decrypt