将汉字变成ascii后是乱码,你有什么用吗
解决方案 »
- CustomLayer.OpenInfoWindow 问题
- 利用反射调用C#写的DLL的时,怎样给DLL中委托类型字段赋值
- c#dataGridView包含combobox的回车相应问题
- 必须声明标量变量@ContentId 的问题
- 请问:怎么能 避免重复触发DataBindingComplete事件?
- 用sql语句填充datatable时,都是select一个列,为什么引用有时得用rows[0][0],有时rows[0][1]
- winform中求怎样使按钮也有倒计时的功能???
- 小弟初学C#,寻求适合学习用的C#源代码,内容最好由浅入深!谢谢!
- 为什么同一个程序,不同设备内存开销不一样???
- 请教一个小问题,谢谢!
- 如何在c#中连接数据库或者创建数据库呢?有100分啊!
- MDI子窗体如何调用MDI父窗体的方法(给分!!)
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;class FileEncrypt { public static Byte[] ConvertStringToByteArray(String s)
{
return (new UnicodeEncoding()).GetBytes(s);
} public static void Main()
{
//创建文件流
FileStream fs = new FileStream("EncryptedFile.txt",FileMode.Create,FileAccess.Write); Console.WriteLine("输入一些要存储在加密文件中的文本::");
String strinput = Console.ReadLine(); Byte[] bytearrayinput=ConvertStringToByteArray(strinput); //具有随机密钥的 DES 实例
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
//从此实例创建 DES 加密器
ICryptoTransform desencrypt = des.CreateEncryptor(); //创建使用 des 加密转换文件流的加密流
CryptoStream cryptostream = new CryptoStream(fs,desencrypt,CryptoStreamMode.Write); //写出 DES 加密文件
cryptostream.Write(bytearrayinput,0,bytearrayinput.Length); cryptostream.Close(); //创建文件流以读回加密文件
FileStream fsread = new FileStream("EncryptedFile.txt",FileMode.Open,FileAccess.Read); //从此 des 实例创建 DES 解密器
ICryptoTransform desdecrypt = des.CreateDecryptor(); //创建加密流集合以便对传入的字节进行读取并执行 des 解密转换
CryptoStream cryptostreamDecr = new CryptoStream(fsread,desdecrypt,CryptoStreamMode.Read);
//输出已解密文件的内容
Console.WriteLine( (new StreamReader(cryptostreamDecr, new UnicodeEncoding())).ReadToEnd() ); Console.WriteLine ();
Console.WriteLine ("按 Enter 键继续...");
Console.ReadLine();
}
}
if(!File.Exists(@"c:\temp.txt"))
File.CreateText(@"c:\temp.txt");
System.IO.StreamWriter sr = new System.IO.StreamWriter(@"c:\temp.txt",false,System.Text.Encoding.ASCII);
sr.WriteLine(cc.ToString());//ps
I think the theory is in this way.but to my surprise,when i perferm
it i fount the file of temp.txt have nothing.
gz together
Dim asciicode As Stringchars = "字"
asciicode = CDec("&H" & Mid(Hex(Asc(chars)), 1, 2)) & " " & CDec("&H" & Mid(Hex(Asc(chars)), 3, 2))
MsgBox asciicode
End Sub
byte[] bytes = unicodeencoding.GetBytes("你好");