小编jcs*_*jcs的帖子

Rijndael填充错误

您好我正在尝试通过Rijaendal加密/解密字符串.我简直无法弄清楚为什么解密会爆炸.我总是以不正确的填充错误结束.抛弃我的一件事是我的加密结果,我将其作为HEX数组返回.它的长度为14个字节.在我的解密函数中,相同的字节数组在从HEX转换时最终具有16个字节.

任何帮助,将不胜感激:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace rjandal
{
    class Program
    {
        static void Main(string[] args)
        {
            string DataForEncrypting = "this is a test";

            string key = string.Empty;
            string iv = string.Empty;

            using (System.Security.Cryptography.RijndaelManaged rmt = new System.Security.Cryptography.RijndaelManaged())
            {
                rmt.KeySize = 256;
                rmt.BlockSize = 128;
                rmt.Mode = System.Security.Cryptography.CipherMode.CBC;
                rmt.Padding = System.Security.Cryptography.PaddingMode.ISO10126;
                rmt.GenerateKey();
                rmt.GenerateIV();
                key = Convert.ToBase64String(rmt.Key);
                iv = Convert.ToBase64String(rmt.IV);
            }

            string encryptedData = _encrypt(DataForEncrypting, key, iv);
            string unencryptedData = _decrypt(key, iv, HexString2Ascii(encryptedData));

            Console.WriteLine(unencryptedData);
            Console.WriteLine(encryptedData);
            Console.ReadKey();
        } …
Run Code Online (Sandbox Code Playgroud)

c# encryption aes rijndael

4
推荐指数
1
解决办法
4393
查看次数

标签 统计

aes ×1

c# ×1

encryption ×1

rijndael ×1