⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class1.cs

📁 C#开发教程 由浅入深 配有实例 是初学者的好帮手
💻 CS
字号:
using System;
using System.IO;
using System.Security.Cryptography;
 
public class CryptoApp
{
    public static void Main(string[] args)
    {
        string sFile = "foo.txt";

        // Encrypt ////////////////////////////////////////////////////

        // Private key and Initialization Vector
        byte[] Key = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
        byte[] IV = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};

        // Lay a CryptoStream on top of a FileStream
        FileStream fs = File.Create(sFile);
        RijndaelManaged rm = new RijndaelManaged();
        CryptoStream cs = new CryptoStream (
//          fs, rm.CreateEncryptor(), CryptoStreamMode.Write);
			fs, rm.CreateEncryptor(Key, IV), CryptoStreamMode.Write);

        // Write to the (crypto) stream
        StreamWriter sw = new StreamWriter(cs);
        sw.WriteLine("Hello World");

        // cleanup
        sw.Close();
        cs.Close();
        fs.Close();


        // Decrypt /////////////////////////////////////////////////////////
        
        fs = File.Open(sFile, FileMode.Open);
        cs = new CryptoStream(
//          fs, rm.CreateDecryptor(), CryptoStreamMode.Read);
			fs, rm.CreateDecryptor(Key, IV), CryptoStreamMode.Read);

        // Read the stream and display the message
        StreamReader sr = new StreamReader(cs);
        Console.Write("Decrypted original message: {0}",
            sr.ReadToEnd());

        sr.Close();
        cs.Close();
        fs.Close();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -