public void Protect() { // Arrange byte[] unprotectedBytes = new byte[] { 1, 2, 3, 4, 5 }; string unprotectedString = HttpServerUtility.UrlTokenEncode(unprotectedBytes); MachineKey45CryptoSystem cryptoSystem = new MachineKey45CryptoSystem(); // Act string protectedString = cryptoSystem.Protect(unprotectedBytes); // Assert Assert.NotEqual(unprotectedString, protectedString); }
public void Unprotect() { // Arrange byte[] unprotectedBytes = new byte[] { 1, 2, 3, 4, 5 }; MachineKey45CryptoSystem cryptoSystem = new MachineKey45CryptoSystem(); // Act string protectedString = cryptoSystem.Protect(unprotectedBytes); byte[] output = cryptoSystem.Unprotect(protectedString); // Assert Assert.Equal(unprotectedBytes, output); }
public void Protect() { // Arrange byte[] expectedInputBytes = new byte[] { 1, 2, 3, 4, 5 }; byte[] expectedOutputBytes = new byte[] { 6, 7, 8, 9, 10 }; string expectedOutputString = HttpServerUtility.UrlTokenEncode(expectedOutputBytes); Func <byte[], string[], byte[]> protectThunk = (input, purposes) => { Assert.Equal(expectedInputBytes, input); Assert.Equal(new string[] { "System.Web.Helpers.AntiXsrf.AntiForgeryToken.v1" }, purposes); return(expectedOutputBytes); }; MachineKey45CryptoSystem cryptoSystem = new MachineKey45CryptoSystem(protectThunk, null); // Act string output = cryptoSystem.Protect(expectedInputBytes); // Assert Assert.Equal(expectedOutputString, output); }
public void Protect() { // Arrange byte[] expectedInputBytes = new byte[] { 1, 2, 3, 4, 5 }; byte[] expectedOutputBytes = new byte[] { 6, 7, 8, 9, 10 }; string expectedOutputString = HttpServerUtility.UrlTokenEncode(expectedOutputBytes); Func<byte[], string[], byte[]> protectThunk = (input, purposes) => { Assert.Equal(expectedInputBytes, input); Assert.Equal(new string[] { "System.Web.Helpers.AntiXsrf.AntiForgeryToken.v1" }, purposes); return expectedOutputBytes; }; MachineKey45CryptoSystem cryptoSystem = new MachineKey45CryptoSystem(protectThunk, null); // Act string output = cryptoSystem.Protect(expectedInputBytes); // Assert Assert.Equal(expectedOutputString, output); }