Esempio n. 1
0
        /// <summary>
        ///     Extracts the secret image from a ModifiedImage.
        /// </summary>
        public async Task ExtractSecretImage()
        {
            var modifiedImageData = await ImageUtilities.GetImageData(this.ModifiedImage);

            if (HeaderUtilities.IsMessageEmbedded(modifiedImageData, this.ModifiedImage.PixelWidth) &&
                HeaderUtilities.GetMessageType(modifiedImageData, this.ModifiedImage.PixelWidth) ==
                MessageType.MonochromeBmp)
            {
                var imageEncoder = new ImageEncoder();

                var secretImageData =
                    imageEncoder.DecodeImage(modifiedImageData, this.ModifiedImage.PixelWidth,
                                             this.ModifiedImage.PixelHeight);

                this.SecretImage = new WriteableBitmap(this.ModifiedImage.PixelWidth, this.ModifiedImage.PixelHeight);

                if (!HeaderUtilities.IsEncrypted(modifiedImageData, this.ModifiedImage.PixelWidth))
                {
                    using var writeStream = this.SecretImage.PixelBuffer.AsStream();
                    await writeStream.WriteAsync(secretImageData, 0, secretImageData.Length);

                    this.EncryptedSecretImage = null;
                }
                else
                {
                    this.EncryptedSecretImage =
                        new WriteableBitmap(this.ModifiedImage.PixelWidth, this.ModifiedImage.PixelHeight);
                    using var encryptedWriteStream = this.EncryptedSecretImage.PixelBuffer.AsStream();
                    await encryptedWriteStream.WriteAsync(secretImageData, 0, secretImageData.Length);

                    using var writeStream = this.SecretImage.PixelBuffer.AsStream();
                    await writeStream.WriteAsync(ImageUtilities.SwitchImageHalves(secretImageData), 0,
                                                 secretImageData.Length);
                }
            }
            else
            {
                throw new ArgumentException("Modified Image doesn't contain Secret Image");
            }
        }
Esempio n. 2
0
 /// <summary>
 ///     Determines whether [is modified image encrypted].
 /// </summary>
 /// <returns>True if the modified image is encrypted</returns>
 public async Task <bool> IsModifiedImageSecretEncrypted()
 {
     return(HeaderUtilities.IsEncrypted(await ImageUtilities.GetImageData(this.ModifiedImage),
                                        this.ModifiedImage.PixelWidth));
 }