public TData Unprotect(string protectedText) { try { if (protectedText == null) { return(default(TData)); } byte[] protectedData = Base64UrlTextEncoder.Decode(protectedText); if (protectedData == null) { return(default(TData)); } byte[] userData = _protector.Unprotect(protectedData); if (userData == null) { return(default(TData)); } TData model = _serializer.Deserialize(userData); return(model); } catch { // TODO trace exception, but do not leak other information return(default(TData)); } }
public TData Unprotect(string protectedText, string purpose) { try { if (protectedText == null) { return(default(TData)); } var protectedData = Base64UrlTextEncoder.Decode(protectedText); if (protectedData == null) { return(default(TData)); } var protector = _protector; if (!string.IsNullOrEmpty(purpose)) { protector = protector.CreateProtector(purpose); } var userData = protector.Unprotect(protectedData); if (userData == null) { return(default(TData)); } return(_serializer.Deserialize(userData)); } catch { // TODO trace exception, but do not leak other information return(default(TData)); } }
public void DataOfVariousLengthRoundTripCorrectly() { for (int length = 0; length != 256; ++length) { var data = new byte[length]; for (int index = 0; index != length; ++index) { data[index] = (byte)(5 + length + (index * 23)); } string text = Base64UrlTextEncoder.Encode(data); byte[] result = Base64UrlTextEncoder.Decode(text); for (int index = 0; index != length; ++index) { Assert.Equal(data[index], result[index]); } } }
public void DataOfVariousLengthRoundTripCorrectly() { var encoder = new Base64UrlTextEncoder(); for (int length = 0; length != 256; ++length) { var data = new byte[length]; for (int index = 0; index != length; ++index) { data[index] = (byte)(5 + length + (index * 23)); } string text = encoder.Encode(data); byte[] result = encoder.Decode(text); for (int index = 0; index != length; ++index) { result[index].ShouldBe(data[index]); } } }