gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 06:09:44 25 4
gpt4 key购买 nike

我想将此代码移植到 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,它工作得很好..

最佳答案

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

enter image description here

您应该能够通过 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);

关于java - C# 相当于 Java 的 KDFCounterBytesGenerator(来自 bouncycaSTLe),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37030830/

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