示例#1
0
        /// <summary>
        /// This function can be used, if an API key must be stored inside the application code,
        /// so it doesn't show up in plain text.
        /// </summary>
        /// <param name="plainMessage">The text to hide.</param>
        /// <param name="obfuscationKey">Key to use for obfuscation, this key is usually hard coded
        /// in the application.</param>
        /// <param name="randomSource">A cryptographically random source.</param>
        /// <returns>Obfuscated message.</returns>
        public static byte[] Obfuscate(byte[] plainMessage, string obfuscationKey, ICryptoRandomSource randomSource)
        {
            EncryptorDecryptor encryptor = new EncryptorDecryptor("obfuscation");

            return(encryptor.Encrypt(
                       plainMessage,
                       obfuscationKey,
                       KeyDerivationCostType.Low,
                       randomSource,
                       "twofish_gcm"));
        }
示例#2
0
        /// <summary>
        /// Reverses a key obfuscated with <see cref="Obfuscate(byte[], string, ICryptoRandomSource)"/>
        /// to its original plain text.
        /// </summary>
        /// <param name="obfuscatedMessage">Obfuscated text.</param>
        /// <param name="obfuscationKey">Key to use for obfuscation, this key is usually hard coded
        /// in the application.</param>
        /// <returns>Original plain message.</returns>
        public static byte[] Deobfuscate(byte[] obfuscatedMessage, string obfuscationKey)
        {
            EncryptorDecryptor encryptor = new EncryptorDecryptor("obfuscation");

            return(encryptor.Decrypt(obfuscatedMessage, obfuscationKey));
        }