How to get Resulting Disgest with WS-UsernameToken?

不问归期 提交于 2019-12-02 02:57:50

The correct steps, in pseudocode, are

1. n = base64decode ("LKqI6G/AikKCQrN0zqZFlg==")
2. s = sha1 (n + "2010-09-16T07:50:45Zuserpassword")
3. resulting_digest = base64encoder (s)

As a reference, the intermediate values are:

1. n = '\x2c\xaa\x88\xe8\x6f\xc0\x8a\x42\x82\x42\xb3\x74\xce\xa6\x45\x96'
2. s = '\xb6\xe3\x92\xa4\x69\x45\x94\x85\xec\xa3\x3a\xb8\x1c\x53\x5e\x78x\67\x85\x2c\x42'

You don't post the result you get, but I think you are using the base64-encoded version of the nonce in the binary string that you are hashing with sha1.

Thanks to @Ottavio 's help, I've figured that I didn't decode the nonce before hashing it with the rest of my entries... The code I used to get to the good result is:

private string GenerateHashedPassword(string nonce, string created, string password)
    {
        byte[] nonceBytes = Convert.FromBase64String(nonce);
        byte[] createdAndPasswordBytes = Encoding.UTF8.GetBytes(created + password);
        byte[] combined = new byte[nonceBytes.Length + createdAndPasswordBytes.Length];

        Buffer.BlockCopy(nonceBytes, 0, combined, 0, nonceBytes.Length);
        Buffer.BlockCopy(createdAndPasswordBytes, 0, combined, nonceBytes.Length, createdAndPasswordBytes.Length);

        return Convert.ToBase64String(SHA1.Create().ComputeHash(combined));
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!