gpt4 book ai didi

c# - CryptDeriveKey 算法名称

转载 作者:行者123 更新时间:2023-11-30 15:35:55 25 4
gpt4 key购买 nike

public byte[] CryptDeriveKey(
string algname,
string alghashname,
int keySize,
byte[] rgbIV
)

谁能告诉我 algname 中有哪些选项?如果我想指定 AES-128 和 AES-256 的加密算法,我应该在 algname 中输入什么?

最佳答案

我不是 100% 确定,但是,algname 是您的算法名称。 keySize 是 key 的大小。

你应该像这样使用AES-128AES-256;

CryptDeriveKey("AES", "SHA1", 128, aes.IV)

CryptDeriveKey("AES", "SHA1", 256, aes.IV)

MSDN 查看更多详细信息.

这是 PasswordDeriveBytes.CryptDeriveKey 方法的反编译代码。

[SecuritySafeCritical]
public byte[] CryptDeriveKey(string algname, string alghashname, int keySize, byte[] rgbIV)
{
if (keySize < 0)
{
throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKeySize"));
}
int algidHash = X509Utils.NameOrOidToAlgId(alghashname, OidGroup.HashAlgorithm);
if (algidHash == 0)
{
throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidAlgorithm"));
}
int algid = X509Utils.NameOrOidToAlgId(algname, OidGroup.AllGroups);
if (algid == 0)
{
throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidAlgorithm"));
}
if (rgbIV == null)
{
throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidIV"));
}
byte[] o = null;
DeriveKey(this.ProvHandle, algid, algidHash, this._password, this._password.Length, keySize << 0x10, rgbIV, rgbIV.Length, JitHelpers.GetObjectHandleOnStack<byte[]>(ref o));
return o;
}

下面是NameOrOidToAlgId方法的反编译代码。

internal static int NameOrOidToAlgId(string oid, OidGroup oidGroup)
{
if (oid == null)
{
return 0x8004;
}
string str = CryptoConfig.MapNameToOID(oid, oidGroup);
if (str == null)
{
str = oid;
}
int algIdFromOid = GetAlgIdFromOid(str, oidGroup);
switch (algIdFromOid)
{
case 0:
case -1:
throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidOID"));
}
return algIdFromOid;
}

关于c# - CryptDeriveKey 算法名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14361367/

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