Home  >  Article  >  Database  >  pl/sql:aes256加密解密

pl/sql:aes256加密解密

WBOY
WBOYOriginal
2016-06-07 14:54:501996browse

调用相应的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;
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn