Example #1
0
        /// <summary>
        /// Embed the text into the image.
        /// </summary>
        /// <param name="text">The text to embed.</param>
        /// <param name="image">The image to embed the text into.</param>
        /// <param name="sharedKey">The shared key used with the common salt.</param>
        /// <param name="salt">The common salt used to generate the key.</param>
        /// <returns>The image containing the embedded text.</returns>
        public Bitmap EmbedText(string text, Bitmap image, string sharedKey, byte[] salt)
        {
            // Create a new derived key.
            byte[] cryptoKey = Nequeo.Cryptography.RandomDerivedKey.Generate(sharedKey, salt);
            Nequeo.Cryptography.AdvancedAES aes = new Cryptography.AdvancedAES();

            // Encrypt the key.
            byte[] encryptedText = aes.EncryptToMemory(Encoding.Default.GetBytes(text), cryptoKey);
            string textBase64    = Nequeo.Conversion.Context.ByteArrayToHexString(encryptedText);

            // Create the image.
            return(Nequeo.Drawing.TextEmbedding.EmbedText(textBase64, image));
        }
Example #2
0
        /// <summary>
        /// Extract the text from the image.
        /// </summary>
        /// <param name="image">The image that contains the text to extract.</param>
        /// <param name="sharedKey">The shared key used with the common salt.</param>
        /// <param name="salt">The common salt used to generate the key.</param>
        /// <returns>The extracted text.</returns>
        public string ExtractText(Bitmap image, string sharedKey, byte[] salt)
        {
            // Create a new derived key.
            byte[] cryptoKey = Nequeo.Cryptography.RandomDerivedKey.Generate(sharedKey, salt);
            Nequeo.Cryptography.AdvancedAES aes = new Cryptography.AdvancedAES();

            // Extract the text.
            string textBase64 = Nequeo.Drawing.TextEmbedding.ExtractText(image);

            byte[] encryptedText = Nequeo.Conversion.Context.HexStringToByteArray(textBase64);
            byte[] decryptedText = aes.DecryptFromMemory(encryptedText, cryptoKey);

            // Return the text.
            return(Encoding.Default.GetString(decryptedText));
        }