简体   繁体   English

HTTP摘要验证-在多个HTTP请求之间共享MD5实例

[英]HTTP Digest Authentication - Share MD5 instance between multiple http requests

I have my own HTTP request class which I am using it as a client to send an HTTP requests to some remote servers. 我有自己的HTTP请求类,将其用作客户端以将HTTP请求发送到某些远程服务器。 I am implementing an HTTP digest authentication and using MD5 instance in order to preform the hash algorithm . 我正在实现HTTP摘要认证,并使用MD5实例来执行哈希算法。 I would like to know what is the efficient way to store the MD5 instance ? 我想知道什么是存储MD5实例的有效方法? I thought about these options: 我考虑了以下选项:

  1. Every request will hold a MD5 instance, so every time that request are being sent we will do : m_md5 = MD5.Create(); 每个请求都将保存一个MD5实例,因此每次发送该请求时,我们都会这样做: m_md5 = MD5.Create();

    How expensive is the 'Create' process ? “创建”过程的成本是多少?

  2. The MD5 instance will be static and will be store out of the request class and we will use the MD5.Create() just once and all the request instance will use the same MD5 instance.Note that a lot of threads are creating instances of the HTTP request class. MD5实例将是静态的,并且将存储在请求类之外,并且我们将仅使用一次MD5.Create(),所有请求实例将使用同一MD5实例。请注意,许多线程正在创建该实例。 HTTP请求类。 Is it thread-safe ? 它是线程安全的吗?

Thnaks. Thnaks。

As Oguz Ozgul Said the second optiond doesn't possible since MD5 doesn't thread-safeas we can see here : 正如Oguz Ozgul 的那样,第二个选项是不可能的,因为MD5不是线程安全的,我们可以在这里看到:

Any public static (Shared in Visual Basic) members of this type are thread safe. 此类型的任何公共static(在Visual Basic中为Shared)成员都是线程安全的。 Any instance members are not guaranteed to be thread safe 不保证任何实例成员都是线程安全的

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

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