小编use*_*063的帖子

"填充无效,无法删除" - 这段代码有什么问题?

每次运行和加密时,输出都是可变的,当我尝试解密时,我得到"填充无效且无法删除".现在和这一天打了一两天,我不知所措.

    private static string strIV = "abcdefghijklmnmo"; //The initialization vector.
    private static string strKey = "abcdefghijklmnmoabcdefghijklmnmo"; //The key used to encrypt the text.

    public static string Decrypt(string TextToDecrypt)
    {
        return Decryptor(TextToDecrypt);
    }

    private static string Encryptor(string TextToEncrypt)
    {
        //Turn the plaintext into a byte array.
        byte[] PlainTextBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(TextToEncrypt);            

        //Setup the AES providor for our purposes.
        AesCryptoServiceProvider aesProvider = new AesCryptoServiceProvider();
        aesProvider.Key = System.Text.Encoding.ASCII.GetBytes(strKey);
        aesProvider.IV = System.Text.Encoding.ASCII.GetBytes(strIV);
        aesProvider.BlockSize = 128;
        aesProvider.KeySize = 256;            
        aesProvider.Padding = PaddingMode.PKCS7;
        aesProvider.Mode = CipherMode.CBC;

        ICryptoTransform …
Run Code Online (Sandbox Code Playgroud)

.net c# encryption aes

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

aes ×1

c# ×1

encryption ×1