示例#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, SecureString obfuscationKey, ICryptoRandomSource randomSource)
        {
            ICryptor encryptor = new Cryptor(CryptorObfuscationPackageName, randomSource);

            return(encryptor.Encrypt(
                       plainMessage,
                       obfuscationKey,
                       KeyDerivationCostType.Low,
                       "xchacha20_poly1305"));
        }
示例#2
0
        /// <summary>
        /// Reverses a key obfuscated with <see cref="Obfuscate(byte[], SecureString, 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, SecureString obfuscationKey)
        {
            ICryptor encryptor = new Cryptor(CryptorObfuscationPackageName, null);

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