相当于Java的KDFCounterBytesGenerator的C#(来自bouncycastle) - java

我想将此代码移植到C#

byte[] result = new byte[length];
byte[] data = ...;
byte[] key = ...;

HMac hMac = new HMac(new SHA256Digest());
KDFCounterBytesGenerator g = new KDFCounterBytesGenerator(hMac);
g.init(new KDFCounterParameters(key, data, 32));
g.generateBytes(result , 0, result .length);

但是我在C#bouncycastle库中找不到任何等效的类。
有什么建议吗?

编辑:
我从Java源代码移植了KDFCounterBytesGenerator,它运行良好。

java参考方案

BouncyCastle has an equivalent library for C#应该包含与Java版本相同的大部分功能(如果不是全部),但语法上会有一些细微的差别:

相当于Java的KDFCounterBytesGenerator的C#(来自bouncycastle) - java

您应该能够通过NuGet安装它,然后相应地进行引用:

// Using statements (for BouncyCastle)
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Crypto.Generators;

// Define your byte[]s
byte[] result = new byte[1];
byte[] data = new byte[2];
byte[] key = new byte[3];

// Build your HMac, Generator and generate your bytes
HMac hMac = new HMac(new Sha256Digest());
Kdf1BytesGenerator g = new Kdf1BytesGenerator(hMac.GetUnderlyingDigest());
g.Init(new Org.BouncyCastle.Crypto.Parameters.KdfParameters(key, data));
g.GenerateBytes(result, 0, result.Length);

45码