C#Rfc2898DeriveBytes结果与PHP PBKDF2不同

时间:2016-09-13 19:10:13

标签: c# php pbkdf2

我尝试使用的SSO软件返回一个URL编码令牌,用户从中生成一个salt值。例如:

$iterations = 1000;
$token="SaIp-gpEFreOJTtrhXuboFAwoBVs0PwgRpKbcTFNAQDRmTN2csxN775kjdhPYSe0tXvctPe0tkf_E48U2Jeetg2"
$salt = base64url_decode($token);
$idAndKey="test@company.com"+"aE1k9-djZ66WbUATqdHbWyJzskMI5ABS0";
$key=hash_pbkdf2('sha1',$idAndKey,$salt,$iterations,32,true);
$enKey= base64url_encode($key);//returns NTZkMjZhOWE5YjU2NDQ2NDY5NWE4MDFlNDIwNTA4NWU=

但是,对于相同的参数,C#返回CPC4OPRZEC1CLVOKDfQK7fv7iwuETvrF0。这是C#代码

HASH_BYTES = 24;
HASH_ITERATIONS = 1000;
var token = "SaIp-gpEFreOJTtrhXuboFAwoBVs0PwgRpKbcTFNAQDRmTN2csxN775kjdhPYSe0tXvctPe0tkf_E48U2Jeetg2";
string idAndKey="test@company.com"+"aE1k9-djZ66WbUATqdHbWyJzskMI5ABS0";
Rfc2898DeriveBytes pbkdf2 = new Rfc2898DeriveBytes(idAndKey, HttpServerUtility.UrlTokenDecode(token)) { IterationCount = HASH_ITERATIONS };
var key = HttpServerUtility.UrlTokenEncode(pbkdf2.GetBytes(HASH_BYTES));

我很感激任何意见。

0 个答案:

没有答案