/// <summary> /// Encrypt a string. /// </summary> /// <param name="plainText">String to be encrypted</param> /// <param name="password">Password</param> public static string Encrypt(string plainText, string password) { if (plainText == null) { return(null); } if (password == null) { password = String.Empty; } // Get the bytes of the string var bytesToBeEncrypted = Encoding.UTF8.GetBytes(plainText); var passwordBytes = Encoding.UTF8.GetBytes(password); // Hash the password with SHA256 passwordBytes = SHA256.Create().ComputeHash(passwordBytes); var bytesEncrypted = Encriptar.Encrypt(bytesToBeEncrypted, passwordBytes); return(Convert.ToBase64String(bytesEncrypted)); }