简体   繁体   English

如何使用C#SDK验证通过AWS SQS传递的数据的完整性?

[英]How do you verify integrity of data passed through AWS SQS using C# SDK?

First off, does the AWS C# SDK self check itself? 首先,AWS C#SDK是否自行检查? Right now, I have code that does stuff like 现在,我的代码就是这样的

md5 checking md5检查

List<string> msgs = new List<string>();
ReceiveMessageResponse response = this.getMessageRoutine(num);
foreach (Message m in response.ReceiveMessageResult.Message) {
   if (m.MD5OfBody.ToUpper() != Global.StringFunctions.CalculateMD5Hash(m.Body)) {
       throw new Exception("TODO IMPLEMENT: RECEIVED MESSAGE IS CORRUPT");
   }
       msgs.Add(m.Body);
}
return msgs;

verifying that the user defined IDs sent out came back in the response , and that the md5 the server generated of the message matches the message sent 验证发出的用户定义的ID是否在响应中返回 ,并且消息生成的服务器的md5与发送的消息匹配

            foreach (SendMessageBatchResultEntry e in response.SendMessageBatchResult.SendMessageBatchResultEntry) {

                foreach (SendMessageBatchRequestEntry r in entry) {
                    if (r.Id == e.Id) {
                        if (Global.StringFunctions.CalculateMD5Hash(r.MessageBody) != e.MD5OfMessageBody.ToUpper()) {
                            throw new Exception("TODO IMPLEMENT THIS: MD5 MISMATCH BETWEEN AWS:LOCAL (" + e.MD5OfMessageBody.ToUpper() + " : " + Global.StringFunctions.CalculateMD5Hash(r.MessageBody)+")");
                        }
                        entry.Remove(r);
                        break;
                    }
                    throw new Exception("TODO IMPLEMENT THIS: INVALID ID IN RESPONSE");
                }
            }
            if (entry.Count != 0) {
                throw new Exception("TODO IMPLEMENT: NOT ALL MESSAGES SENT HAD A CORRESPONDING CALLBACK");
            }

Is there a better implementation of something like this already created, something like request.checkResponse(response) ? 是否有更好的实现已经创建的这样的东西,比如request.checkResponse(response)?

The most recent version of the AWS SDK for .NET ( 1.5.23 ) includes the MD5 hash check as part of sending a single message, sending a batch of messages, and receiving messages. 最新版本的AWS SDK for .NET1.5.23 )包括MD5哈希检查,作为发送单个消息,发送一批消息和接收消息的一部分。 If that does not work for you, we would love to hear why and how we could make it better. 如果这对您不起作用,我们很乐意听到为什么以及如何让它变得更好。

Thanks! 谢谢!

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

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