编程语言
首页 > 编程语言> > CryptDeriveKey算法名称

CryptDeriveKey算法名称

作者:互联网

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

有人可以告诉我algname中有哪些选项吗?如果要为AES-128和AES-256指定加密算法,应该在algname中输入什么?

解决方法:

我不确定100%,但是algname是您的算法名称. keySize是密钥的大小.

您应该像这样使用AES-128和AES-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;
}

标签:password-encryption,encryption,aes,cryptography,c
来源: https://codeday.me/bug/20191031/1975331.html