问题描述
DECLARE
l_string NVARCHAR2(600) := '123456';
checksum NVARCHAR2(600);
BEGIN
DBMS_OUTPUT.DISABLE;
DBMS_OUTPUT.ENABLE(1000000);
DBMS_OBFUSCATION_TOOLKIT.md5 (input_string => l_string, checksum_string => checksum);
DBMS_OUTPUT.PUT_LINE(RAWTONHEX(utl_raw.cast_to_raw(checksum)));
END;
期望值:e10adc3949ba59abbe56e057f20f883e
Expected value: e10adc3949ba59abbe56e057f20f883e
但返回:FFFD00390049FFFD0059FFFDFFFD0056FFFD000FFFFD003E
But it returns: FFFD00390049FFFD0059FFFDFFFD0056FFFD000FFFFD003E
注意,我想维护nvarchar2数据类型.来自校验和变量的值存储在类型为nvarchar2的列中.
Note I want to maintain nvarchar2 datatype. The value from checksum variable gets stored in column that is of type nvarchar2.
我知道md5接受并返回varchar2中的数据.但是,如果有人可以使用nvarchar2数据类型帮助我弄清楚这一点,那就太好了.
I am aware that md5 accepts and returns data in varchar2. But if someone can help me figure this out using nvarchar2 data type, that would be great.
NLS_CHARACTERSET = AL32UTF8
The NLS_CHARACTERSET = AL32UTF8
推荐答案
以下内容应通过使用hash()的dbms_crypto进行工作
The following should work via dbms_crypto using hash()
declare
l_src nvarchar2(100) := '123456';
l_raw_hash raw(100);
begin
l_raw_hash := dbms_crypto.hash(to_clob(l_src), dbms_crypto.HASH_MD5);
dbms_output.put_line(l_raw_hash);
end;
结果:E10ADC3949BA59ABBE56E057F20F883E
Result: E10ADC3949BA59ABBE56E057F20F883E
l_raw_hash将为原始格式.您可以使用UTL_RAW将其转换为另一种数据类型.只要确保您的显示器显示正确的字符集,否则一切都会看起来很有趣.
l_raw_hash will be in raw format. You can use UTL_RAW to convert it to another datat type. Just make sure your display is showing the proper character set or thing will look interesting.
这篇关于在Oracle DBMS_OBFUSCATION_TOOLKIT.MD5中将NVARCHAR2转换为MD5哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!