【发布时间】:2018-09-13 03:17:46
【问题描述】:
我正在使用 PHP 进行 SSO 实现,该实现对用 C# 编写的系统进行身份验证。下面是一些伪代码来演示:
$token = "MqsXexqpYRUNAHR_lHkPRic1g1BYhH6bFNVPagEkuaL8Mf80l_tOirhThQYIbfWYErgu4bDwl-7brVhXTWnJNQ2";
$id = "bob@company.com";
$ssokey = "7MpszrQpO95p7H";
$idAndKey = $id . $ssokey;
$salt = base64_decode(substr($token, 0, -1));
$hashed = hash_pbkdf2("sha256", $idAndKey, mb_convert_encoding($salt, 'UTF-16LE'), 1000, 24, false);
$data = base64_encode($hashed);
这个输出:NWZiMTBhZmNhNTlmYzMxMTEzMThhZmVl
这是我正在集成的系统的 C# 版本:
var token = "MqsXexqpYRUNAHR_lHkPRic1g1BYhH6bFNVPagEkuaL8Mf80l_tOirhThQYIbfWYErgu4bDwl-7brVhXTWnJNQ2";
var id = "bob@company.com";
var ssokey = "7MpszrQpO95p7H";
string idAndKey = id + ssokey;
var salt = HttpServerUtility.UrlTokenDecode(token);
var pbkdf2 = new Rfc2898DeriveBytes(idAndKey, salt) {IterationCount = 1000};
var key = HttpServerUtility.UrlTokenEncode(pbkdf2.GetBytes(24));
Console.WriteLine(key.ToString());
这个输出:aE1k9-djZ66WbUATqdHbWyJzskMI5ABS0
我不知道如何让我的 PHP 代码做同样的事情。我感觉它属于salt 一代。
我尝试将 C# HttpServerUtility.UrlTokenDecode 函数转换为 PHP,如下所示:
function UrlTokenDecode($token) {
$numPadChars = substr($token, -1);
// add the padded count to the end
$salt = substr($token, 0, -1) . $numPadChars;
// Transform the "-" to "+", and "*" to "/"
$salt = str_replace('-', '+', str_replace('*', '/', $salt));
// base64_decode
$salt = base64_decode($salt);
return $salt;
}
这并没有让我到达我需要去的地方。哈!
这是用于吸收 LMS。他们的方法的文档在这里:https://support.absorblms.com/hc/en-us/articles/222446647-Incoming-Absorb-Single-Sign-On#Methods
谢谢!
【问题讨论】:
-
一件事是
Rfc2898DeriveBytes使用 sha1 作为哈希函数,而不是 sha256。 -
谢谢! Absorb 文档特别说明了 sha256,这让我很失望。我已经更新了我的代码,但仍然没有得到想要的结果。还有其他想法吗?