如何获得带有WS-UsernameToken的结果摘要? [英] How to get Resulting Disgest with WS-UsernameToken?

查看:107
本文介绍了如何获得带有WS-UsernameToken的结果摘要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从

我目前正在尝试使用指南中给出的相同条目来复制结果摘要.

I'm currently trying to reproduce the Resulting Digest using the same entries given in the guide...

这是我的代码:

private string GenerateHashedPassword(string nonce, string created, string password)
    {
        byte[] nonceBytes = Encoding.UTF8.GetBytes(nonce);
        byte[] createdBytes = Encoding.UTF8.GetBytes(created);
        byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
        byte[] combined = new byte[createdBytes.Length + nonce.Length + passwordBytes.Length];
        //N-C-P
        Buffer.BlockCopy(nonceBytes, 0, combined, 0, nonceBytes.Length);
        Buffer.BlockCopy(createdBytes, 0, combined, nonceBytes.Length, createdBytes.Length);
        Buffer.BlockCopy(passwordBytes, 0, combined, nonceBytes.Length + createdBytes.Length, passwordBytes.Length);

        return Convert.ToBase64String(SHA1.Create().ComputeHash(combined));
    }

当我使用我的函数时:

string digestPassword = GenerateHashedPassword("LKqI6G/AikKCQrN0zqZFlg==","2010-09-16T07:50:45Z","userpassword");//Values from guide

我的函数返回的结果与指南中的结果不同...

My function doesn't return the same result as in the guide...

我的功能出了什么问题?? 为什么我无法获得相同的输出?

What's wrong with my function?? Why can't I get the same output??

推荐答案

由于@Ottavio的帮助,我发现在将哈希数与其余条目进行哈希运算之前,我并没有对它进行解码.我用来取得良好效果的代码是:

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));
    }

这篇关于如何获得带有WS-UsernameToken的结果摘要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆