I studied Oracle's encryption algorithm one or two days ago, combined with my practical experience and Oracle9iSuppliedPLSQLPackagesandTypesReference. Encryption (encr
I studied Oracle's encryption algorithm one or two days ago, combined with my practical experience and Oracle9i Supplied PL/SQL Packages and Types Reference. Encryption (encr
I studied Oracle's encryption algorithm one or two days ago, combined with my practical experience and Oracle9i Supplied PL/SQL Packages and Types Reference. encryption (encrypt) decryption (decrypt) uses the Oracle DBMS_OBFUSCATION_TOOLKIT package.
With this package, we can perform DES, Triple DES, or MD5 encryption on the data.
DESGETKEY -- generate a key for the DES algorithm
DES3GETKEY -- generate a key for the Triple DES algorithm
DESENCRYPT -- encrypt data using the DES algorithm
DESDECRYPT -- decrypt data using the DES algorithm
DES3ENCRYPT -- use the Triple DES algorithm to encrypt data
DES3DECRYPT -- decrypt data using the DES algorithm
MD5-encrypt data using the MD5 Algorithm
Triple DES (3DES) is a far stronger cipher than DES; the resulting ciphertext (encrypted data) is much harder to break using an exhaustive search: 2 ** 112 or 2 ** 168 attempts instead of 2 ** 56 attempts what is the concept? Taking the current computing power as an example,
Uppose you build a computer capable of making 1000 attempts each second. How long wocould it take to exhaust 2 to the 56 (256) attempts? It will go supernova into billions of years before you'll finish.
The following describes how to encrypt the string: password:
DECLARE
Input_string VARCHAR2 (16): = 'Password ';
Key_string VARCHAR2 (8): = 'oracle9i ';
Encrypted_string VARCHAR2 (2048 );
Decrypted_string VARCHAR2 (2048 );
Error_in_input_buffer_length EXCEPTION;
PRAGMA EXCEPTION_INIT (error_in_input_buffer_length,-28232 );
INPUT_BUFFER_LENGTH_ERR_MSG VARCHAR2 (100): =
'*** Des input buffer not a multiple of 8 BYTES ***';
BEGIN
Dbms_output.put_line ('>========= begin test ========= ');
Dbms_output.put_line ('> Input string:' |
Input_string );
-- BEGIN <-- ignore this, typo in Oracle's documentation
Dbms_obfuscation_toolkit.DESEncrypt (
Input_string => input_string,
Key_string => key_string,
Encrypted_string => encrypted_string );
Dbms_output.put_line ('> Encrypted string:' |
Encrypted_string );
-- Add DESDecrypt as shown, change raw to key_string
Dbms_obfuscation_toolkit.DESDecrypt (
Input_string => encrypted_string,
Key_string => key_string,
Decrypted_string => decrypted_string );
Dbms_output.put_line ('> Decrypted output:' |
Decrypted_string );
Dbms_output.put_line ('> ');
If input_string =
Decrypted_string THEN
Dbms_output.put_line ('> DES Encryption and Decryption successful ');
End if;
EXCEPTION
WHEN error_in_input_buffer_length THEN
Dbms_output.put_line ('>' | INPUT_BUFFER_LENGTH_ERR_MSG );
END;
Running result:
=========== Begin test ============
> Input string: password
> Encrypted string:.] % .? -I
> Decrypted output: password
>
> DES Encryption and Decryption successful
Here, the encrypted string has different SQL/plus versions. Because the character set is different, it must be noted that the encrypted string (input_string) must be a multiple of 8, in fact, the encrypted string is also a multiple of 8. If not, the result is:
=========== Begin test ============
> Input string: passwo1rd
> *** Des input buffer not a multiple of 8 BYTES ***
,