人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動態(tài)

C#的加密與解密

發(fā)布日期:2022-01-07 17:17 | 文章來源:源碼之家
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();
}
}

版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部