簡體   English   中英

用於加密大字節數組的高效加密算法

[英]Efficient encryption algorithm for encrypting large byte array

到目前為止,對於我最近的項目,我一直在使用SDES加密任何二進制文件。 無疑,該算法易於實現。 但是同時,它不適合加密大文件,因為它以1字節大小的純文本作為輸入,即一次加密1字節。 任何關於更有效的加密算法的建議都將受到贊賞。


以下是對圖像文件進行SDES的簡單實現:

  • 這部分代碼對包括頭在內的整個數據字節進行加密。 您可以將ASCII或UTF-8格式的數據字節保存在文件中,並通過某些不安全的通道進行傳輸。 解密並轉換為圖像文件后,您可以使用幻數編程

      Conversion.Convert cvt = new Conversion.Convert(); Console.WriteLine("Please enter the RGB/GRAY/BINARY image path: "); string path = Console.ReadLine(); byte []arrayPT = Conversion.Convert.ImageToBinary(path); // Get the binary data from the image byte []arrayCT = new byte[arrayPT.Length]; int i = 0; foreach (byte element in arrayPT) { arrayCT[i] = ob.Encrypt(element); Console.Write("{0}", arrayCT[i]); //Convert the contents of arrayCT[] into char and save into a file i++; } 
  • 使用此方法僅加密顏色信息,即像素值。

      SDES ob = new SDES(key); Bitmap img = new Bitmap(imgpath); Color pixelColor, pixels; //byte[] buff = new byte[3 * img.Height * img.Width]; for (int i = 0; i < img.Width; i++) { for (int j = 0; j < img.Height; j++) { pixels = img.GetPixel(i, j); pixelColor = Color.FromArgb(ob.Encrypt(pixels.R), ob.Encrypt(pixels.G), ob.Encrypt(pixels.B)); img.SetPixel(i, j, pixelColor); } } img.Save(newEncryptedImg); 

您是否考慮過使用C#集成加密功能? 它們位於System.Security.Cryptography 有一個CryptoStream似乎允許基於Stream的密碼轉換。

http://msdn.microsoft.com/zh-CN/library/system.security.cryptography.cryptostream(v=vs.110).aspx

這些類可以追溯到IIRC相當不錯的OS集成加密數據包。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM