我想将此代码移植到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,它运行良好..
答案 0 :(得分:0)
BouncyCastle has an equivalent library for C#应该包含大多数(如果不是全部)与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);