欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

pl/sql:aes256加密解密

程序员文章站 2022-06-11 16:33:05
...

调用相应的API对BLOB数据 相应的加密和解密 PL/SQL 加密解密 --加密function encrypt_aes256 (p_blob in blob, p_key in varchar2) return blobas l_key_raw raw(32); l_returnvalue blob;begin /* Purpose: encrypt blob Remarks: p_key should be 32 charac

调用相应的API对BLOB数据 相应的加密和解密 PL/SQL 加密解密
--加密
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;