今天上午一直在翻OMA的SyncML 1.1 协议,卡在用户验证的地方,按照协议上的例子怎么算也算不出来预期的结果。

根据协议正文,MD5验证的算法很简单,用伪代码来表示就是这样:

result = base64( md5( base64( md5( username + ":" + password)) + ":" + nonce) );

用php写出来就是:

function computehash($username, $password, $nonce){
    
return base64_encode(pack('H*', md5(base64_encode(pack('H*', md5("$username:$password"))) . ":$nonce")));
}

但是用协议里指定的参数:

username="Bruce1" , password="OhBehave" , nonce="Nonce"

无论如何也算不出协议里给的值"Zz6EivR3yeaaENcRN6lpAQ==", 而是 "+MEIKFrF8Qdou2B1H2YmXw=="

一气之下用 .NET 写了一个,结果也是相同的。

 nonce)
{
    System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();

    md5.ComputeHash(Encoding.ASCII.GetBytes(user 
+ ":" + password));

    
string s = Convert.ToBase64String(md5.Hash) + ":" + nonce;

    md5.ComputeHash(Encoding.ASCII.GetBytes(s));
    
return Convert.ToBase64String(md5.Hash);
}

经过多方搜索,终于在 这里 发现了原因:协议写错了。正确的参数应该是:

username="Bruce2" , password="OhBehave" , nonce="Nonce"

我Faint…

相关文章:

  • 2022-12-23
  • 2021-07-19
  • 2021-08-01
  • 2021-05-03
  • 2022-12-23
  • 2021-07-13
  • 2021-06-21
  • 2021-10-08
猜你喜欢
  • 2021-07-29
  • 2021-09-01
  • 2022-12-23
  • 2021-08-31
  • 2022-02-10
  • 2021-11-18
  • 2022-03-01
相关资源
相似解决方案