Esempio n. 1
0
        public static string DecryptText(
            this ICipher cipher,
            byte[] encryptedText)
        {
            if (cipher == null)
            {
                throw new ArgumentNullException(nameof(cipher));
            }

            if (encryptedText == null)
            {
                return(null);
            }

            return(cipher.DecryptString(encryptedText));
        }
Esempio n. 2
0
        /// <summary>
        /// Decrypts the <paramref name="encryptedText64"/> to a string, provided the crypto text was encoded with Base64.
        /// </summary>
        /// <param name="cipher">The cipher.</param>
        /// <param name="encryptedText64">The crypto text encoded Base64.</param>
        /// <returns>The decrypted text.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="cipher"/> is <see langword="null"/>.</exception>
        public static string DecryptText64(
            this ICipher cipher,
            string encryptedText64)
        {
            if (cipher == null)
            {
                throw new ArgumentNullException(nameof(cipher));
            }

            if (encryptedText64 == null)
            {
                return(null);
            }

            var base64 = cipher.Base64Encoded;

            cipher.Base64Encoded = false;

            var decryptedData = cipher.DecryptString(Convert.FromBase64String(encryptedText64));

            cipher.Base64Encoded = base64;

            return(decryptedData);
        }