我需要通过Oracle查询检查sha512加密中的数据。
示例查询:
SELECT * FROM text WHERE SHA512(id) = '$id'
答案 0 :(得分:1)
Oracle提供DBMS_CRYPTO
包来处理加密和哈希。
您可以按照此查询中显示的方式将SHA哈希计算和比较与某个字符串常量结合使用:
select *
from text t
where
lower( -- to guarantee same character case
rawtohex( -- convert hash to string representation
dbms_crypto.hash( -- hash calculation function
utl_raw.cast_to_raw(t.id), -- need to convert a string before passing it to
-- function in parameter because otherwise
-- it casted to RAW directly with hextoraw().
6 -- dbms_crypto.HASH_SH512 - for Oracle 12c only
)
)
)
=
lower( -- to guarantee same character case
:some_id_sha2_const_parameter -- parameter string to compare with
)
不幸的是,由于缺乏支持,您无法在Oracle 11g中处理SHA-512
哈希值。但是Oracle 12c可以实现这一点。
文档:
DBMS_CRYPTO package in Oracle 11g
DBMS_CRYPTO package in Oracle 12c
您还必须考虑两件事: