pl/sql:aes256加密解密

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

--加密
function encrypt_aes256 (p_blob in blob,
                         p_key in varchar2) return blob
as
  l_key_raw                      raw(32);
  l_returnvalue                  blob;
begin

  /*

  Purpose:    encrypt blob

  Remarks:    p_key should be 32 characters (256 bits / 8 = 32 bytes)

  Who     Date        Description
  ------  ----------  -------------------------------------
  MBR     20.01.2011  Created

  */
  --获得 raw类型的key
  l_key_raw := utl_raw.cast_to_raw (p_key);
  
  dbms_lob.createtemporary (l_returnvalue, false);

  dbms_crypto.encrypt (l_returnvalue, p_blob, g_encryption_type_aes, l_key_raw);

  return l_returnvalue;

end encrypt_aes256;

--解密 
function decrypt_aes256 (p_blob in blob,
                         p_key in varchar2) return blob
as
  l_key_raw                      raw(32);
  l_returnvalue                  blob;
begin

  /*

  Purpose:    decrypt blob

  Remarks:    p_key should be 32 characters (256 bits / 8 = 32 bytes)

  Who     Date        Description
  ------  ----------  -------------------------------------
  MBR     20.01.2011  Created

  */

  l_key_raw := utl_raw.cast_to_raw (p_key);

  dbms_lob.createtemporary (l_returnvalue, false);

  dbms_crypto.decrypt (l_returnvalue, p_blob, g_encryption_type_aes, l_key_raw);

  return l_returnvalue;

end decrypt_aes256;