Esempio n. 1
0
        public static string Decrypt(string encryptedText, string password)
        {
            if (encryptedText == null)
            {
                return(null);
            }

            if (password == null)
            {
                password = String.Empty;
            }
            var bytesToBeDecrypted = Convert.FromBase64String(encryptedText);
            var passwordBytes      = Encoding.UTF8.GetBytes(password);

            passwordBytes = SHA256.Create().ComputeHash(passwordBytes);

            var bytesDecrypted = Cryptology.Decrypt(bytesToBeDecrypted, passwordBytes);

            return(Encoding.UTF8.GetString(bytesDecrypted));
        }
Esempio n. 2
0
        public static string Encrypt(this string password)
        {
            if (plainText == null)
            {
                return(null);
            }

            if (password == null)
            {
                password = String.Empty;
            }

            var bytesToBeEncrypted = Encoding.UTF8.GetBytes(plainText);
            var passwordBytes      = Encoding.UTF8.GetBytes(password);


            passwordBytes = SHA256.Create().ComputeHash(passwordBytes);

            var bytesEncrypted = Cryptology.Encrypt(bytesToBeEncrypted, passwordBytes);

            password = Convert.ToBase64String(bytesEncrypted);
            return(password);
        }