public override string ToString() { StringBuilder Content = new StringBuilder(); // Go through the contents and build a // typical query string foreach (string key in base.Keys) { Content.Append(HttpUtility.UrlEncode(key)); Content.Append("="); Content.Append(HttpUtility.UrlEncode(base[key])); Content.Append("&"); } // Remove the last '&' Content.Remove(Content.Length - 1, 1); // Now encrypt the contents using DPAPI byte[] EncryptedData = ProtectedData.Protect( Encoding.UTF8.GetBytes(Content.ToString()), null, DataProtectionScope.LocalMachine); // Convert encrypted byte array to a URL-legal string // This would also be a good place to check that data // is not larger than typical 4KB query string return(HexEncoding.GetString(EncryptedData)); }
public void OddNumberOfHexDigitsShouldRoundTripWithLeadingZero() { var hex = "A12F5"; var bytes = HexEncoding.GetBytes(hex); var hex2 = HexEncoding.GetString(bytes); Assert.Equal("0" + hex.ToLower(), hex2.ToLower()); }
public void HexStringsShouldRoundTrip() { var hex = "0A12F5"; var bytes = HexEncoding.GetBytes(hex); var hex2 = HexEncoding.GetString(bytes); Assert.Equal(hex.ToLower(), hex2.ToLower()); }
public void ByteArraysShouldRoundTrip() { var bytes = new byte[] { 10, 18, 245 }; var hex = HexEncoding.GetString(bytes); var bytes2 = HexEncoding.GetBytes(hex); Assert.Equal(bytes, bytes2); }
public void GetString_RandomBytes() { var buf = new byte[1000]; (new Random()).NextBytes(buf); var expected = BitConverter.ToString(buf).Replace("-", ""); var actual = HexEncoding.GetString(buf); Assert.AreEqual(expected, actual); }
public void GetString_AllByteValues() { var buf = new byte[1]; for (byte testByte = 0; testByte < 0xff; testByte++) { buf[0] = testByte; var actual = HexEncoding.GetString(buf); Assert.AreEqual(testByte.ToString("X2"), actual); } }
protected void GivenEncryption() { #if NET452 Configuration.Encryption = new EncryptionElement { Enabled = true, Provider = "AES", Key = HexEncoding.GetString(KeyGenerator.GenerateAesKey().GetSymmetricKey()) }; #endif #if NETCOREAPP2_0 var section = Configuration.GetSection("encryption"); section["enabled"] = "true"; section["provider"] = "aes"; section["key"] = HexEncoding.GetString(KeyGenerator.GenerateAesKey().Key); #endif }
public void ShouldReturnAllLowercaseLetters_WhenAskingForAllLowercase() { string value = HexEncoding.GetString(new byte[] { 170, 170, 170, 170 }); Assert.Equal("aaaaaaaa", value); }
public void ShouldReturnAllFs_WhenAllBitsAreSet() { string value = HexEncoding.GetString(new byte[] { 255, 255, 255, 255 }); Assert.Equal("ffffffff", value); }
public void ShouldReturnHighByteValues_WhenOnlyHighByteValuesArePassedIn() { string value = HexEncoding.GetString(new byte[] { 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240 }); Assert.Equal("102030405060708090a0b0c0d0e0f0", value); }
public void ShouldReturnLowByteValues_WhenOnlyLowByteValuesArePassedIn() { string value = HexEncoding.GetString(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }); Assert.Equal("0102030405060708090a0b0c0d0e0f", value); }
public void ShouldReturn00_When0IsPassedIn() { string value = HexEncoding.GetString(new byte[] { 0 }); Assert.Equal("00", value); }
public void ShouldReturnEmptyString_WhenAnEmptyArrayIsPassedIn() { string value = HexEncoding.GetString(new byte[0]); Assert.Equal("", value); }
public void ShouldThrowArgumentNullException_WhenNullIsPassedIn() { Assert.Throws <ArgumentNullException>(() => HexEncoding.GetString(null)); }
public void GetString_EmptyByteArray() { var actual = HexEncoding.GetString(new byte[0]); Assert.AreEqual("", actual); }