使用DBMS_crypto加密/解密null

时间:2014-03-18 15:25:20

标签: oracle encryption null dbms-crypto

我在互联网上搜索加密空值并解密时发生的事情。

到目前为止,在我的实验中。在我的表中,我有一个时间戳列。 我有几行数据,在这几行中,我有适当的时间戳和空值混合。

我试过这个:

select count(*) from mytable where key = 'currLoginTime' and
  to_timestamp(clob_substr(decrypt(value,?), 19, 1), 'YYYY-MM-DD HH24:MI:SS') > ?

第一个参数是我的私钥,第二个参数是我要比较的日期。

我一直收到以下异常:

ORA-01841: (full) year must be between -4713 and +9999, and not be 0;
nested exception is java.sql.SQLDataException: ORA-01841: (full) year must be
between -4713 and +9999, and not be 0

我猜测原始的空值被解密为0.有人可以确认或解释一下吗?我真的很难过。

1 个答案:

答案 0 :(得分:2)

加密或解密null会导致null。以任何其他方式工作都没有多大意义。为了证明:

var typ number;
var key varchar2(32);
begin
  :typ := dbms_crypto.encrypt_aes256
     + dbms_crypto.chain_cbc
     + dbms_crypto.pad_pkcs5;
  :key := dbms_crypto.randombytes(32);
end;
/

set null '(null)'

select dbms_crypto.encrypt(src=>utl_i18n.string_to_raw(null, 'AL32UTF8'),
  typ=>:typ, key=>:key) as encrypted
from dual;

ENCRYPTED                    
------------------------------
(null)                         

select utl_i18n.raw_to_char(dbms_crypto.decrypt(src=>null,
  typ=>:typ, key=>:key)) as plain
from dual;

PLAIN                        
------------------------------
(null)                         

您获得的错误不是因为空值。至少有一个非空值似乎无效 - 加密的原始纯文本值不是您to_timestamp()调用期望的格式。

相关问题