简体   繁体   English

为什么这个byte []数组不同并且在返回到调用方法时保持一个完全不同的值?

[英]Why this byte[] array is different and holds a total different value when it is returned to calling method?

I am using .NET reflector to debug a console application calling a WSE3.0 service which requires signing & encrypting the message using username token element. 我正在使用.NET反射器来调试调用WSE3.0服务的控制台应用程序,该服务需要使用用户名令牌元素对消息进行签名和加密。 Our service provider uses WSE so I need to use that or replicate that same logic of signing and encrypting if I need to use non .net client. 我们的服务提供商使用WSE,因此如果我需要使用非.net客户端,我需要使用它或复制相同的签名和加密逻辑。 To find out how that actual message signing happens (so that I can replicate that using NON .NET clients) I used .NET reflector to debug the code. 要了解实际的消息签名是如何发生的(以便我可以使用NON .NET客户端进行复制),我使用.NET反射器来调试代码。

MessageSignature.BuildSignedInfo calls HMACSHA1SignatureFormatter.Sign which actually signs the message and returns the hmac, which is a byte[] array, to MessageSignature.BuildSignedInfo. MessageSignature.BuildSignedInfo调用HMACSHA1SignatureFormatter.Sign,它实际对消息进行签名,并将一个byte []数组的hmac返回给MessageSignature.BuildSignedInfo。 Below are the 2 methods 以下是两种方法

private byte[] BuildSignedInfo(SignatureFormatter formatter)
{
    this.SignedInfo.SignatureMethod = formatter.AlgorithmURI;
    return formatter.Sign(this.CanonicalizeSignedInfo());
}


public override byte[] Sign(Stream data)
{
    HMACSHA1 hmacsha = new HMACSHA1(this._key);
    return hmacsha.ComputeHash(data);
}

This is how the byte array looks like in watch windows. 这就是字节数组在监视窗口中的样子。

Watch window in sign method of HMACSHA1SignatureFormatter 在HMACSHA1SignatureFormatter的符号方法中观察窗口

在HMACSHA1SignatureFormatter的符号方法中观察窗口

Watch window of that returned byte[] array in MessageSignature.BuildSignedInfo (this calls that sign method to get byte[] array) 在MessageSignature.BuildSignedInfo中查看返回的byte []数组的窗口(这称为sign方法获取byte []数组)

在Buildsignedinfo方法中观察窗口

I am stepping through the code and there are no intermediate methods which gets called in between them. 我正在逐步完成代码,并且没有在它们之间调用的中间方法。 Would there be any reason why that would happen? 有什么理由会发生这种情况吗?

A few possibilities: 一些可能性:

  1. Maybe ComputeHash is not rewinding the stream, so the second call from the QuickWatch window hashes a different portion of the stream? 也许ComputeHash没有倒带流,所以QuickWatch窗口的第二次调用会对流的不同部分进行哈希处理? Check the stream.Position before and after each call. 检查每次通话前后的stream.Position。

  2. If you are stepping through decompiled Microsoft code, then that code is likely optimized, which can sometimes reorder calls. 如果您正在逐步使用反编译的Microsoft代码,那么该代码可能已经过优化,有时可能会重新排序调用。 It may be that the hash function actually has not been called yet, or the result is not where you think it is, as you step through the method. 当您逐步执行该方法时,可能实际上还没有调用散列函数,或者结果不在您认为的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM