dimanche 28 septembre 2014

How to use encrypt and decrypt method for images in c# winforms


Vote count:

0




I want to use encrypted images from local folder and use it in my application, So that no one can see or modify the images. I really don't know how to do this but i'm trying to make it. I'm using picture box in user control form. Getting linked as by giving image Location from the property of picture box.


I'm using buttons to open forms, when the form get opened it will search the location, and displays it. Please help me to do it. I tried this. I got it from Stackoverflow here i din't get anything...



public class EncryptFile_DecryptFile
{
#region Encrypt Images & save it
public string EncryptFile(Image img, string ImagePath_to_Save)
{
byte[] ImageBytes;
ImageBytes = imageToByteArray(img);

for (int i = 0; i < ImageBytes.Length; i++)
{
ImageBytes[i] = (byte)(ImageBytes[i] ^ 5);
}
File.WriteAllBytes(ImagePath_to_Save, ImageBytes);
return ImagePath_to_Save;
}
#endregion
#region Convert Image in to Byte
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return ms.ToArray();
}
#endregion


#region Decrypt Image & save it
public Stream DecryptFile(string encryptedImageFile){
byte[] ImageBytes;

ImageBytes = File.ReadAllBytes(encryptedImageFile);

for (int i = 0; i < ImageBytes.Length; i++){
ImageBytes[i] = (byte)(ImageBytes[i] ^ 5);
}

return new MemoryStream(ImageBytes);
}
#endregion
}


asked 30 secs ago







How to use encrypt and decrypt method for images in c# winforms

Aucun commentaire:

Enregistrer un commentaire