Following Sample PL/SQL Block can be used to test the ENCRYPT and DECRYPT procedure from the DBMS_CRYPTO package.
DECLARE
encryption_type PLS_INTEGER := DBMS_CRYPTO.ENCRYPT_DES
+ DBMS_CRYPTO.CHAIN_CBC
+ DBMS_CRYPTO.PAD_PKCS5;
/*
ENCRYPT_DES is the encryption algorithem. Data Encryption Standard. Block cipher.
Uses key length of 56 bits.
CHAIN_CBC Cipher Block Chaining. Plaintext is XORed with the previous ciphertext
block before it is encrypted.
PAD_PKCS5 Provides padding which complies with the PKCS #5: Password-Based
Cryptography Standard
*/
encryption_key RAW (32) := UTL_RAW.cast_to_raw('MyEncryptionKey');
-- The encryption key for DES algorithem, should be 8 bytes or more.
p_plainText VARCHAR2(30) := 'MY TEST WORD';
encrypted_raw RAW (2000);
decrypted_raw RAW (2000);
BEGIN
encrypted_raw := DBMS_CRYPTO.ENCRYPT
(
src => UTL_RAW.CAST_TO_RAW (p_plainText),
typ => encryption_type,
key => encryption_key
);
DBMS_OUTPUT.PUT_LINE('Encrypted Values : ' || encrypted_raw);
decrypted_raw := DBMS_CRYPTO.DECRYPT
(
src => encrypted_raw,
typ => encryption_type,
key => encryption_key
);
DBMS_OUTPUT.PUT_LINE('Decrypted Values : ' || UTL_RAW.CAST_TO_VARCHAR2 (decrypted_raw));
END;
/
Here is the output :
DECLARE
encryption_type PLS_INTEGER := DBMS_CRYPTO.ENCRYPT_DES
+ DBMS_CRYPTO.CHAIN_CBC
+ DBMS_CRYPTO.PAD_PKCS5;
/*
ENCRYPT_DES is the encryption algorithem. Data Encryption Standard. Block cipher.
Uses key length of 56 bits.
CHAIN_CBC Cipher Block Chaining. Plaintext is XORed with the previous ciphertext
block before it is encrypted.
PAD_PKCS5 Provides padding which complies with the PKCS #5: Password-Based
Cryptography Standard
*/
encryption_key RAW (32) := UTL_RAW.cast_to_raw('MyEncryptionKey');
-- The encryption key for DES algorithem, should be 8 bytes or more.
p_plainText VARCHAR2(30) := 'MY TEST WORD';
encrypted_raw RAW (2000);
decrypted_raw RAW (2000);
BEGIN
encrypted_raw := DBMS_CRYPTO.ENCRYPT
(
src => UTL_RAW.CAST_TO_RAW (p_plainText),
typ => encryption_type,
key => encryption_key
);
DBMS_OUTPUT.PUT_LINE('Encrypted Values : ' || encrypted_raw);
decrypted_raw := DBMS_CRYPTO.DECRYPT
(
src => encrypted_raw,
typ => encryption_type,
key => encryption_key
);
DBMS_OUTPUT.PUT_LINE('Decrypted Values : ' || UTL_RAW.CAST_TO_VARCHAR2 (decrypted_raw));
END;
/
Here is the output :
No comments:
Post a Comment