简体   繁体   中英

Efficient encryption algorithm for encrypting large byte array

For my recent project, so far I have been using SDES for encrypting any binary file. Undoubtedly, the algorithm is simple to implement; but at the same time it is not suitable for encrypting large files as it takes plaintext of size 1 byte as input ie Encrypts 1 byte at a time. Any suggestions on more efficient encryption algorithm is appreciated.


Below is the simple implementation of SDES on image files:

  • This segment of code encrypts the entire data bytes including the header. You can save the data bytes in form of ASCII or UTF-8 in a file and transmit over some insecure channel. Upon decryption and reconverting to an image file you can use magic number programming .

      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++; } 
  • Use this approach to encrypt only the color information ie pixel values.

      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); 

Have you considered using the C# integrated cryptography functions? They are found in System.Security.Cryptography . There is a CryptoStream that seems to allow Stream based cryptographic transformations.

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

Those classes go back to the OS integraed cryptography packet which IIRC is pretty good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM