I currently have 2 winform programs that make use of the machinekey.protect and unprotect functions, but everything protected in program 1 can't be unprotected in program 2 and the other way around I found out if I change the filename of program 1 to program 2 it works.

var plaintextBytes = Encoding.UTF8.GetBytes("this is a test");

var encryptedValue = Convert.ToBase64String(MachineKey.Protect(plaintextBytes, "password"));
//then I do some other code and program 2 need to unprotect.
var bytes = Convert.FromBase64String(encryptedValue);

var output = MachineKey.Unprotect(bytes, "password");

I hope that someone would know how I could get the two programs to read from the same protected source. I'm pretty new to programming in general, just trying to learn :)

UPDATE: Changing "Assembly name" in both programs to be the same solves the problem, but I still want to find out the reason for this.

0 Answers