相关疑难解决方法(0)

如何将十六进制字符串转换为字节数组?

我们可以使用C#中的内置函数将十六进制字符串转换为字节数组,还是必须为此创建自定义方法?

c# encoding hex

260
推荐指数
4
解决办法
47万
查看次数

解密异常 - 要解密的数据长度无效

我在C#应用程序中工作.我们有将数据存储在文件中的常用方法.这些方法加密数据并将其存储在文件系统上.当我们需要数据时,ReadData方法解密数据并返回纯文本.

如果文本的大小很小,这段代码在正常情况下工作正常.但是对于下面给出的示例文本,解密代码抛出异常 - 要解密的数据长度无效.

该异常发生在行

        // close the CryptoStream
        x_cryptostream.Close();
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的方法,但没有运气.有些人可以帮忙.

为什么我要加密已经加密的数据 - 我只是试图使用庞大应用程序的常用方法存储在一个文件中.常见的方法storedata(key,data)NAD readdata(key)做加密/解密我无法回避.

   public static byte[] Decrypt(byte[] ciphertext, string Key, string IV)
    {
        byte[] k = Encoding.Default.GetBytes(Key);
        byte[] iv = Encoding.Default.GetBytes(IV);

        // create the encryption algorithm
        SymmetricAlgorithm x_alg = SymmetricAlgorithm.Create("Rijndael");
        x_alg.Padding = PaddingMode.PKCS7;

        // create an ICryptoTransform that can be used to decrypt data
        ICryptoTransform x_decryptor = x_alg.CreateDecryptor(k, iv);

        // create the memory stream
        MemoryStream x_memory_stream = new MemoryStream();

        // create the CryptoStream that ties …
Run Code Online (Sandbox Code Playgroud)

c# encryption cryptography rijndael

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

标签 统计

c# ×2

cryptography ×1

encoding ×1

encryption ×1

hex ×1

rijndael ×1