private static void Encrypt(object files) { List<string> imgFiles = files as List<string>; /* Parallel.ForEach(imgFiles, fileName => { } ); */ foreach (String fileName in imgFiles) { Image image = Image.FromFile(fileName); Image thumb = image.GetThumbnailImage(120, 120, () => false, IntPtr.Zero); string newFile = Path.ChangeExtension(fileName, "thumb"); string loc = "Thumbnails\\" + Path.GetFileName(newFile); thumb.Save(loc); string name = Path.GetFileNameWithoutExtension(fileName); string type = Path.GetExtension(fileName); EncryptedImage encryptedImage = new EncryptedImage(); encryptedImage.Name = name; encryptedImage.PathThumb = loc; encryptedImage.PathOriginal = fileName; encryptedImage.Type = type; LocalData.insertEncryptedImage(encryptedImage); ImageEncoder.EncodeImage(fileName, encryptedImage); } }
public static void updateEncryptedImage(EncryptedImage encryptedImage) { StringBuilder sb = new StringBuilder(); sb.Append("idx='" + encryptedImage.Idx + "',"); sb.Append("name='" + encryptedImage.Name + "',"); sb.Append("key='" + encryptedImage.Key + "',"); sb.Append("type='" + encryptedImage.Type + "',"); sb.Append("pathEncrypted='" + encryptedImage.PathEncrypted + "',"); sb.Append("pathThumb='" + encryptedImage.PathThumb + "',"); sb.Append("pathOriginal='" + encryptedImage.PathOriginal + "'"); DBHandler.executeCmd("UPDATE Images SET " + sb + " WHERE pathOriginal='" + encryptedImage.PathOriginal + "'"); }
public void ConvertImageToGrayScale(string src, string dst) { double scale = Math.Pow(2.0, 40); var img = ImageIo.ReadImage(src); var encryptedImage = EncryptedImage.FromBmp(img, encryptor, encoder, scale, PolyModulusDegree / 2); // Call server. Server just has the encoder and evaluator. var encryptedGrayScaleImage = _imageProcessorServer.ConvertToGrayScale(encryptedImage); var decryptedGrayScaleImage = encryptedGrayScaleImage.DecryptFromVector(decryptor, encoder); var dataP = PlaintextImageProcessor.ConvertToGrayScale(img); ImageIo.SaveImage(dst, decryptedGrayScaleImage); }
public static int WIDTH = 400; //set new image width #endregion Fields #region Methods public static void EncodeImage(String dir, EncryptedImage imageData) { Image inputImage; Bitmap inputBitmap; int[,] path = new int[SWAPS, 2]; String ImageKey; //retreving image from directory inputImage = Image.FromFile(dir); inputBitmap = new Bitmap(inputImage); //resize the pic to 400 x 300 pix inputBitmap = Resize_Image(inputBitmap, WIDTH, HIGHT); //save program id 13 bit in image <0 .. 12> make_id(inputBitmap); //save user id 32 bit in image <13 .. 44> make_user_id(inputBitmap); //get image id String imageID = LocalData.getUserProperties().ImageId; //save image id 32 bit in image <45 .. 76> make_image_id(inputBitmap, imageID); //Encode the image Random_Shuffle(path); ImageKey = Save_Path(path); Encode_Image(path, inputBitmap); //send image info to server bool send = true;// send_to_server(ImageKey); if (send) { //save encoded image string loc = "EncodedImages\\" + Path.GetFileName(dir); inputBitmap.Save(loc); //save image in dataBase save_in_dataBase(imageData, imageID, ImageKey, loc); } }
/// <summary> /// Converts an image to grayscale. /// </summary> /// <param name="image">The image.</param> /// <param name="evaluator">The evaluator.</param> /// <returns></returns> public EncryptedImage ConvertToGrayScale( EncryptedImage image) { var rCtx = MultiplyPlain(image._rValueVector, RMultiplePtx); var gCtx = MultiplyPlain(image._gValueVector, GMultiplePtx); var bCtx = MultiplyPlain(image._bValueVector, BMultiplePtx); var grayCtx = AddMany(rCtx, gCtx, bCtx); // WARNING: NULL values can cause error on decryption. return(new EncryptedImage( image._width, image._height, image._aValues, null, null, null, grayCtx, grayCtx, grayCtx)); // int grayScale = (int)(((actualColor.R * 0.3) + (actualColor.G * 0.59) + (actualColor.B * 0.11))); }
private static void save_in_dataBase(EncryptedImage imageData, String imageId, String imageKey, String imagePath) { imageData.Idx = imageId; imageData.Key = imageKey; imageData.PathEncrypted = imagePath; LocalData.updateEncryptedImage(imageData); }
public static void insertEncryptedImage(EncryptedImage encryptedImage) { DBHandler.insert("INSERT INTO Images(idx , name , key , type , pathEncrypted , pathThumb , pathOriginal) VALUES('" + encryptedImage.Idx + "' , '" + encryptedImage.Name + "' , '" + encryptedImage.Key + "' , '" + encryptedImage.Type + "' ,'" + encryptedImage.PathEncrypted + "' , '" + encryptedImage.PathThumb + "' , '" + encryptedImage.PathOriginal + "')"); }