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

HTTP Digest Authentication - Share MD5 instance between multiple http requests

我有自己的 HTTP 请求 class,我将其用作客户端以向某些远程服务器发送 HTTP 请求。 我正在实施 HTTP 摘要身份验证并使用 MD5 实例来执行哈希算法。 我想知道存储 MD5 实例的有效方法是什么? 我考虑了这些选项:

  1. 每个请求都会持有一个 MD5 实例,所以每次发送该请求时我们都会做:m_md5 = MD5.Create();

    'Create' 流程有多贵?

  2. MD5 实例将是静态的并将存储在请求之外 class 我们将只使用一次 MD5.Create() 并且所有请求实例将使用相同的 MD5 instance.Note 许多线程正在创建 HTTP 请求的实例 class。它是线程安全的吗?

谢谢。

作为奥古兹·奥兹古尔 the second optiond doesn't possible since MD5 doesn't thread-safeas we can see here:

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe