文件加密问题。 [英] Problem with file encryption.

查看:78
本文介绍了文件加密问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序中,我使用Triple DES算法加密和解密.dat文件。它加密但是desination文件中的所有字符都替换为这些字符:�$?ï/ <%



这是代码:



in my program, I am encrypting and decrypting a .dat file using the Triple DES algorithm. It encrypts but all the characters in the desination file are replaced with these characters: �$ï/‹%

Here's the code:

public byte[] Transform(byte[] input, ICryptoTransform CryptoTransform)
       {
           // create the necessary streams
           MemoryStream memStream = new MemoryStream();
           CryptoStream cryptStream = new CryptoStream(memStream, CryptoTransform, CryptoStreamMode.Write);

           // transform the bytes as requested
           cryptStream.Write(input, 0, input.Length);
           cryptStream.FlushFinalBlock();

           // Read the memory stream and
           // convert it back into byte array
           memStream.Position = 0;
           byte[] result = memStream.ToArray();

           // close and release the streams
           memStream.Close();
           cryptStream.Close();

           // hand back the encrypted buffer
           return result;
       }

推荐答案

?ï/ <%



以下是代码:



ï/‹%

Here's the code:

public byte[] Transform(byte[] input, ICryptoTransform CryptoTransform)
       {
           // create the necessary streams
           MemoryStream memStream = new MemoryStream();
           CryptoStream cryptStream = new CryptoStream(memStream, CryptoTransform, CryptoStreamMode.Write);

           // transform the bytes as requested
           cryptStream.Write(input, 0, input.Length);
           cryptStream.FlushFinalBlock();

           // Read the memory stream and
           // convert it back into byte array
           memStream.Position = 0;
           byte[] result = memStream.ToArray();

           // close and release the streams
           memStream.Close();
           cryptStream.Close();

           // hand back the encrypted buffer
           return result;
       }


您期望加密做什么?将其更改为这是加密数据的文本?





加密数据不具有可读性:这就是整体理念。当你使用Triple DES时,它返回一个加密的字节数组......因为它应该是。
What did you expect encryption to do? Change it to text which says "This is encrypted data."?


Encrypted data is not meant to be readable: that's the whole idea. When you use Triple DES it returns an array of bytes which are encrypted...because it is supposed to.


这篇关于文件加密问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆