示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public string DecryptText(string input, string password)
        {
            // Get the bytes of the string
            byte[] bytesToBeDecrypted = Convert.FromBase64String(input);
            byte[] passwordBytes      = Encoding.UTF8.GetBytes(password);
            passwordBytes = SHA256.Create().ComputeHash(passwordBytes);
            byte[] bytesDecrypted = AESManaged.AES_Decrypt(bytesToBeDecrypted, passwordBytes);
            string result         = Encoding.UTF8.GetString(bytesDecrypted);

            return(result);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public string EncryptText(string input, string password)
        {
            // Get the bytes of the string
            byte[] bytesToBeEncrypted = Encoding.UTF8.GetBytes(input);
            byte[] passwordBytes      = Encoding.UTF8.GetBytes(password);
            // Hash the password with SHA256
            passwordBytes = SHA256.Create().ComputeHash(passwordBytes);
            byte[] bytesEncrypted = AESManaged.AES_Encrypt(bytesToBeEncrypted, passwordBytes);
            string result         = Convert.ToBase64String(bytesEncrypted);

            return(result);
        }