且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从SQL Server和Oracle获取散列值并比较它们?

更新时间:2023-02-23 12:49:53


$ b

In SQL Server:

select upper(substring(sys.fn_sqlvarbasetostr(hashbytes('MD5','A')),3,32));

结果:

result:

7FC56270E7A70FA81A5935B72EACBE29

在Oracle中:

In Oracle :

select rawtohex(
    DBMS_CRYPTO.Hash (
        UTL_I18N.STRING_TO_RAW ('A', 'AL32UTF8'),
        2)
    ) from dual;

结果:

result:

7FC56270E7A70FA81A5935B72EACBE29

确保您的字符串完全相同(区分大小写)。这里我用'A'作为一个简单的例子,但它可以是任何字符串。

Make sure your strings are exactly the same (case sensitive). Here I used 'A' as a simple example, but it could be any string really.

如果通过转换为大字符串来避免数据类型差异,应该能够在不同平台上生成相同的md5散列。请注意,SQL Server在该哈希前加了一个'0x'来表示十六进制表示,我用该子字符串剥离。

If you avoid data type differences by converting to a big string, you should be able to produce the same md5 hash on different platforms. Note that SQL Server prepended a '0x' to the hash to denote hex representation, which I stripped with the substring.