/// <summary> /// Extracts the secret text message. /// </summary> public async Task ExtractSecretMessage() { var modifiedImageData = await ImageUtilities.GetImageData(this.ModifiedImage); if (HeaderUtilities.IsMessageEmbedded(modifiedImageData, this.ModifiedImage.PixelWidth) && HeaderUtilities.GetMessageType(modifiedImageData, this.ModifiedImage.PixelWidth) == MessageType.Text) { var textEncoder = new TextEncoder( HeaderUtilities.GetBitsPerColorChannel(modifiedImageData, this.ModifiedImage.PixelWidth)); this.SecretMessage = textEncoder.DecodeMessage(modifiedImageData); } else { throw new ArgumentException("Modified Image doesn't contain Secret Text Message"); } }
/// <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"); } }
/// <summary> /// Gets the type of the secret message. /// </summary> /// <returns></returns> public async Task <MessageType> GetSecretType() { return(HeaderUtilities.GetMessageType(await ImageUtilities.GetImageData(this.ModifiedImage), this.ModifiedImage.PixelWidth)); }