在.NET框架中,如果我们需要创建自己的密码算法,我们可以创建自己的类,如下所示:
public class MyAlgorithm: System.Security.Cryptography.HashAlgorithm
{
}但在.NET核心中,它似乎非常有限,因为
public abstract class HashAlgorithm : IDisposable
{
protected HashAlgorithm();
public virtual int HashSize { get; }
public byte[] ComputeHash(byte[] buffer);
public byte[] ComputeHash(byte[] buffer, int offset, int count);
public byte[] ComputeHash(Stream inputStream);
public void Dispose();
public abstract void Initialize();
protected virtual void Dispose(bool disposing);
protected abstract void HashCore(byte[] array, int ibStart, int cbSize);
protected abstract byte[] HashFinal();
}它没有像HashSizeValue或State这样的东西。
我们是否仍应使用HashAlgorithm作为.NET核心中自己算法的基类?
发布于 2017-04-12 08:15:04
在您的类中,实现
public override int HashSize => 256;(或你所拥有的价值)。
如果您正在使用HashSizeValue,请将其更改为HashSize。
如果您使用的是State,请将其作为protected int State阅读。在“完整”HashAlgorithm中,它由两个公共方法(TransformBlock和TransformFinalBlock)使用。如果您需要它(而且您正在使用TransformBlock和TransformFinalBlock),那么从.NET Core HashAlgorithm的更新版本中复制它(您可以在github上找到它)。如果您只是检查它,那么您就不需要它了,您可以对它进行注释(因为只有两个缺少的方法会编写它)。
https://stackoverflow.com/questions/43362925
复制相似问题