gpt4 book ai didi

.net-core - BouncyCasSTLe.NetCore : Impossible to find the CryptoApiRandomGenerator class

转载 作者:行者123 更新时间:2023-12-03 04:19:11 26 4
gpt4 key购买 nike

我已经安装了 BouncyCaSTLe.NetCore 包来创建自签名证书,但我找不到 CryptoApiRandomGenerator 类。

正常吗?如果是,替代品是什么?

最佳答案

您可以实现自己的 CryptoApiRandomGenerator。像这样的事情:

public class MyCryptoApiRandomGenerator
: IRandomGenerator
{
private readonly RNGCryptoServiceProvider rndProv;

public NetMatchCryptoApiRandomGenerator()
{
rndProv = new RNGCryptoServiceProvider();
}

#region IRandomGenerator Members

public virtual void AddSeedMaterial(byte[] seed)
{
// I don't care about the seed
}

public virtual void AddSeedMaterial(long seed)
{
// I don't care about the seed
}

public virtual void NextBytes(byte[] bytes)
{
rndProv.GetBytes(bytes);
}

public virtual void NextBytes(byte[] bytes, int start, int len)
{
if (start < 0)
throw new ArgumentException("Start offset cannot be negative", "start");
if (bytes.Length < (start + len))
throw new ArgumentException("Byte array too small for requested offset and length");

if (bytes.Length == len && start == 0)
{
NextBytes(bytes);
}
else
{
byte[] tmpBuf = new byte[len];
rndProv.GetBytes(tmpBuf);
Array.Copy(tmpBuf, 0, bytes, start, len);
}
}

#endregion
}

目前 .Net Core 中还没有隐式实现。

关于.net-core - BouncyCasSTLe.NetCore : Impossible to find the CryptoApiRandomGenerator class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44003102/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com