让 Oracle 的 MD5 与 PHP 的 MD5 匹配
我正在尝试将 PHP 生成的 MD5 校验和与 Oracle 10g 生成的 MD5 校验和进行比较。 然而,我似乎正在将苹果与橙子进行比较。
以下是我测试比较的方法:
//md5 tests
//php md5
print md5('testingthemd5function');
print '<br/><br/>';
//oracle md5
$md5query = "select md5hash('testingthemd5function') from dual";
$stid = oci_parse($conn, $md5query);
if (!$stid) {
$e = oci_error($conn);
print htmlentities($e['message']);
exit;
}
$r = oci_execute($stid, OCI_DEFAULT);
if (!$r) {
$e = oci_error($stid);
echo htmlentities($e['message']);
exit;
}
$row = oci_fetch_row($stid);
print $row[0];
Oracle 中的 md5 函数(在上面的查询中看到)使用“dbms_obfuscation_toolkit.md5”包(?),定义如下:
CREATE OR REPLACE FUNCTION PORTAL.md5hash (v_input_string in varchar2) return varchar2
is
v_checksum varchar2(20);
begin
v_checksum := dbms_obfuscation_toolkit.md5 (input_string => v_input_string);
return v_checksum;
end;
我的 PHP 页面上显示的是:
29dbb90ea99a397b946518c84f45e016
)Û¹©š9{”eÈOEà
任何人都可以帮忙吗?我让两者匹配吗?
I'm trying to compare an MD5 checksum generated by PHP to one generated by Oracle 10g. However it seems I'm comparing apples to oranges.
Here's what I did to test the comparison:
//md5 tests
//php md5
print md5('testingthemd5function');
print '<br/><br/>';
//oracle md5
$md5query = "select md5hash('testingthemd5function') from dual";
$stid = oci_parse($conn, $md5query);
if (!$stid) {
$e = oci_error($conn);
print htmlentities($e['message']);
exit;
}
$r = oci_execute($stid, OCI_DEFAULT);
if (!$r) {
$e = oci_error($stid);
echo htmlentities($e['message']);
exit;
}
$row = oci_fetch_row($stid);
print $row[0];
The md5 function (seen in the query above) in Oracle uses the 'dbms_obfuscation_toolkit.md5' package(?) and is defined like this:
CREATE OR REPLACE FUNCTION PORTAL.md5hash (v_input_string in varchar2) return varchar2
is
v_checksum varchar2(20);
begin
v_checksum := dbms_obfuscation_toolkit.md5 (input_string => v_input_string);
return v_checksum;
end;
What comes out on my PHP page is:
29dbb90ea99a397b946518c84f45e016
)Û¹©š9{”eÈOEà
Can anyone help me in getting the two to match?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我得到了相同的“数字或值错误”,并发现两个函数一起工作:
然后您可以运行此查询来获取校验和:
第二个函数的作用与在您提供的函数上发出 Bazz 提供的 SELECT 语句相同,但我宁愿不必执行 rawToHex --> 每个查询内部的转化率较低。 每次使用查询时,都会留下太多可能出错的事情。 我认为它也可能更快,因为它是在创建时而不是运行时编译的,但我对此可能是错的。
I got the same "numeric or value error" and found that two functions together work:
Then you can run this query to get your checksum:
That second function does the same thing as issuing the SELECT statement provided by Bazz on the function you provide, but I prefer to not have to do the rawToHex --> lower conversion inside of every query. That leaves too many things to potentially go wrong every time you use the query. I think it may be faster too since it is compiled at creation time instead of at runtime, but I may be wrong about that.
如果您想在 Oracle 中拥有 md5,可以使用以下方法:
In case you would want to have the md5 in Oracle, you can use this method:
创建一个如下所示的函数:
并像这样调用它:
似乎“dbms_obfuscation_toolkit.md5”并没有真正以原始格式返回,因此需要调用“utl_raw.cast_to_raw”。 虽然我可能是错的,但应该有更好的解释。
Create a function like the following:
and call it like this:
it seems that "dbms_obfuscation_toolkit.md5" does not really return in raw format, hence the need to call "utl_raw.cast_to_raw". I could be wrong though, there should be a better explanation for this.
看来从 Oracle 查询中打印的是 md5 校验和的原始字节流,由于大多数八位字节不是 ascii 字符,所以被破坏了。 首先尝试将其转换为十六进制。
It appears that what's being printed from the Oracle query is the raw bytestream of the md5 checksum, mangled because most of those octets won't be ascii characters. Try converting it to hexadecimal first.
它返回原始字节,您需要将其转换为十六进制。
It returns raw bytes, you need to convert that into hex.