Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;指定的密码模式对此算法无效;在.NET内核中,但在.NET标准中工作_C#_Encryption_.net Core_Aes_.net Standard - Fatal编程技术网

C# &引用;指定的密码模式对此算法无效;在.NET内核中,但在.NET标准中工作

C# &引用;指定的密码模式对此算法无效;在.NET内核中,但在.NET标准中工作,c#,encryption,.net-core,aes,.net-standard,C#,Encryption,.net Core,Aes,.net Standard,我正在尝试解密aes加密文件。我能够在.NET标准中成功地解密该文件。但当我在.NETCore中使用相同的代码时,我得到了以下异常 System.Security.Cryptography.CryptographicException: 'Specified cipher mode is not valid for this algorithm.' 这是我用来解密的代码 public void FileDecrypt(string inputFile, string outputFile, s

我正在尝试解密aes加密文件。我能够在.NET标准中成功地解密该文件。但当我在.NETCore中使用相同的代码时,我得到了以下异常

System.Security.Cryptography.CryptographicException: 'Specified cipher mode is not valid for this algorithm.'
这是我用来解密的代码

public void FileDecrypt(string inputFile, string outputFile, string password)
    {
        byte[] passwordBytes = System.Text.Encoding.UTF8.GetBytes(password);
        byte[] salt = new byte[32];

        FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);
        fsCrypt.Read(salt, 0, salt.Length);

        RijndaelManaged AES = new RijndaelManaged();
        AES.KeySize = 256;
        AES.BlockSize = 128;
        var key = new Rfc2898DeriveBytes(passwordBytes, salt, 50000);
        AES.Key = key.GetBytes(AES.KeySize / 8);
        AES.IV = key.GetBytes(AES.BlockSize / 8);
        AES.Padding = PaddingMode.PKCS7;
        AES.Mode = CipherMode.CFB;

        using (CryptoStream cs = new CryptoStream(fsCrypt, AES.CreateDecryptor(), CryptoStreamMode.Read))
        {
            using (FileStream fsOut = new FileStream(outputFile, FileMode.Create))
            {
                int read;
                byte[] buffer = new byte[1048576];

                while ((read = cs.Read(buffer, 0, buffer.Length)) > 0)
                {
                    fsOut.Write(buffer, 0, read);
                }
            }
        }
    }
若我在.NET内核中删除密码模式并解密,我将得到一个无效的异常

System.Security.Cryptography.CryptographicException: 'Padding is invalid and cannot be removed.'
我更改了不同的填充模式并进行了尝试,但输出文件无效(未正确递减)

为什么我在.Net内核中得到密码模式无效异常,而不是在.Net标准中? 我应该在.NET Core中做什么更改才能正确解密

我正在使用

.NET Core SDK (reflecting any global.json):
Version:   2.1.503

目前,.NET Core只支持三种模式(CBC=1、CTS=5、ECB=2)


看起来它目前没有在.NET Core中实现,但应该在.NET Core 3中实现。