I am currently encrypting strings as follows:
public static string Encrypt(this string DecryptedValue)
{
if (string.IsNullOrWhiteSpace(DecryptedValue)) { return string.Empty; }
return HttpServerUtility.UrlTokenEncode(MachineKey.Protect(Encoding.UTF8.GetBytes(DecryptedValue.Trim())));
}
public static string Decrypt(this string EncryptedValue)
{
if (string.IsNullOrWhiteSpace(EncryptedValue)) { return string.Empty; }
return Encoding.UTF8.GetString(MachineKey.Unprotect(HttpServerUtility.UrlTokenDecode(EncryptedValue)));
}
However, when I move the production database to a development server (to test a new version before I deploy), these functions are unable to decrypt data already stored in the database (I assume that this is because of my usage of the MachineKey).
Is there some way that I could modify the above extensions so that I could encrypt/decrypt the same database on multiple machines without writing something complicated?