官方文档 关于dbms_crypto包
http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_crypto.htm
CreateOrReplacePackage cryptoAs
Function encrypt(p_original_stringInVarchar2)ReturnVarchar2;
Function decrypt(p_encrypted_stringInVarchar2)ReturnVarchar2;
End crypto;
/
CreateOrReplacePackageBody cryptoAs
original_string Varchar2(32767);
encrypted_string Varchar2(32767);
decrypted_string Varchar2(32767);
-- stores encrypted binary text
encrypted_raw Raw(2000);
-- stores decrypted binary text
decrypted_raw Raw(2000);
-- key length 256 bits (32 bytes)
--num_key_bytes NUMBER := 256/8;
--key_bytes_raw RAW(32) :=DBMS_CRYPTO.RANDOMBYTES(num_key_bytes);
-- stores 256-bit encryption key
key_bytes_raw Raw(16) :=utl_i18n.string_to_raw('F77E8E04888416B3',
'AL32UTF8');
key_iv Raw(16) := utl_i18n.string_to_raw('0102030405060708',
'AL32UTF8');
-- total encryption type
encryption_type Pls_Integer := dbms_crypto.encrypt_aes128 +
dbms_crypto.chain_cbc +
dbms_crypto.pad_pkcs5;
Function encrypt(p_original_stringInVarchar2)ReturnVarchar2Is
Begin
original_string :=p_original_string;
encrypted_raw :=dbms_crypto.encrypt(src => utl_i18n.string_to_raw(original_string,
'AL32UTF8'),
typ=> encryption_type,
key =>key_bytes_raw);
encrypted_string := rawtohex(encrypted_raw);
Return encrypted_string;
End;
Function decrypt(p_encrypted_stringInVarchar2)ReturnVarchar2Is
Begin
encrypted_string := p_encrypted_string;
encrypted_raw :=hextoraw(encrypted_string);
decrypted_raw :=dbms_crypto.decrypt(src => encrypted_raw,
typ=> encryption_type,
key=> key_bytes_raw);
decrypted_string := utl_i18n.raw_to_char(decrypted_raw,'AL32UTF8');
Return decrypted_string;
End;
End crypto;
/