2013-07-13 147 views
2

我似乎無法找到使用AES 256加密加密在C#中的文件AES 256加密文件C#

任何人都不會有一些示例代碼的乾淨的例子嗎?

回答

4

這裏是asnwer上述問題

UnicodeEncoding ue = new UnicodeEncoding(); 

       byte[] key = ue.GetBytes(password); 
       string cryptFile = outputFile; 
       using (FileStream fileCrypt = new FileStream(cryptFile, FileMode.Create)) 
       { 
        using (AesManaged encrypt = new AesManaged()) 
        { 
         using (CryptoStream cs = new CryptoStream(fileCrypt, encrypt.CreateEncryptor(key, key), CryptoStreamMode.Write)) 
         { 
          using (FileStream fileInput = new FileStream(inputFile, FileMode.Open)) 
          { 
           encrypt.KeySize = 256; 
           encrypt.BlockSize = 128; 
           int data; 
           while ((data = fileInput.ReadByte()) != -1) 
            cs.WriteByte((byte)data); 
          } 
         } 
        } 
       }