最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#的加密與解密

互聯(lián)網(wǎng)   發(fā)布時間:2008-10-08 19:02:40   作者:佚名   我要評論
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
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()
{
//創(chuàng)建文件流
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();
//從此實例創(chuàng)建 DES 加密器
ICryptoTransform desencrypt = des.CreateEncryptor();
//創(chuàng)建使用 des 加密轉(zhuǎn)換文件流的加密流
CryptoStream cryptostream = new CryptoStream(fs,desencrypt,CryptoStreamMode.Write);
//寫出 DES 加密文件
cryptostream.Write(bytearrayinput,0,bytearrayinput.Length);
cryptostream.Close();
//創(chuàng)建文件流以讀回加密文件
FileStream fsread = new FileStream("EncryptedFile.txt",FileMode.Open,FileAccess.Read);
//從此 des 實例創(chuàng)建 DES 解密器
ICryptoTransform desdecrypt = des.CreateDecryptor();
//創(chuàng)建加密流集合以便對傳入的字節(jié)進行讀取并執(zhí)行 des 解密轉(zhuǎn)換
CryptoStream cryptostreamDecr = new CryptoStream(fsread,desdecrypt,CryptoStreamMode.Read);
//輸出已解密文件的內(nèi)容
Console.WriteLine( (new StreamReader(cryptostreamDecr, new UnicodeEncoding())).ReadToEnd() );
Console.WriteLine ();
Console.WriteLine ("按 Enter 鍵繼續(xù)...");
Console.ReadLine();
}
}

相關(guān)文章

最新評論

旌德县| 石家庄市| 垦利县| 建水县| 德化县| 文水县| 泰州市| 许昌市| 宜都市| 曲阳县| 乃东县| 乃东县| 满洲里市| 石城县| 万州区| 民权县| 喀什市| 应城市| 五峰| 怀集县| 永城市| 尼玛县| 平邑县| 株洲市| 西畴县| 松江区| 岳阳市| 乐昌市| 双牌县| 都江堰市| 锡林郭勒盟| 台南县| 蓬莱市| 高密市| 修武县| 唐海县| 固原市| 丹巴县| 日照市| 松溪县| 武城县|