0

I need to decrypt/encrypt based on the machine key. How can we generate the key and IV values? Is there any tool to do like this?

I am using .NET Framework 3.5

To tell what is required Ex:

//24 byte or 192 bit key and IV for AES
private static byte[] KEY_192 = { ... };
private static byte[] IV_192 = { ... };
4

1 回答 1

2

I guess you could technically hack this by leveraging the FormAuthentication class, it uses the same encryption under the hood e.g.

var dataTicket = new FormsAuthenticationTicket(1, String.Empty, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), true, "encrypt me!");
var encryptedData = FormsAuthentication.Encrypt(dataTicket);
...
dataTicket = FormsAuthentication.Decrypt(encryptedData);
Console.WriteLine(dataTicket.UserData); // "encrypt me!"

A better solution would be to upgrade to .NET 4 and use the MachineKey class directly.

于 2013-01-07T14:49:07.003 回答