-1

I want c# to write a piece of HPKP code into a text box.

What a piece of apache HKPK code looks like:

Header always set Public-Key-Pins "pin-sha256=\"base64+primary==\"; pin-sha256=\"base64+backup==\"; max-age=5184000; includeSubDomains"

what i tried doing in c#:

apacheTextBox.Text = ("Header always set Public-Key-Pins ") + ("pin-sha256=\"base64+primary==\"; pin-sha256=\"base64+backup==\"; max-age=5184000; includeSubDomains");

which results in (entered into a text box but shown in code here for clear viewing):

Header always set Public-Key-Pins pin-sha256="base64+primary=="; pin-sha256="base64+backup=="; max-age=5184000; includeSubDomains

As you can see there are two quotation marks missing between:

pin-sha256="base64+primary=="; pin-sha256="base64+backup=="; max-age=5184000; includeSubDomains

So how do i get c# to write quotation marks?

  • Hint: the `\ ` in `\"base64` is also missing – Hans Kesting Mar 11 '16 at 12:14
  • You've sort of answered it in your question, in that the things that you want to output as `\"` are coming out as `"`. Your next question will be "how do I output \" - the answer being the same, escape it with another "\". – James Thorpe Mar 11 '16 at 12:14
  • make this : `apacheTextBox.Text = =@your string;` you don't need to \" in order to output " –  Mar 11 '16 at 12:32

2 Answers2

2

\" will escape the quote in c# so it will print the quote as a character. Try this

apacheTextBox.Text = ("Header always set Public-Key-Pins ") + ("\"pin-sha256=\"base64+primary==\"; pin-sha256=\"base64+backup==\"; max-age=5184000; includeSubDomains\"");
James Dev
  • 2,979
  • 1
  • 11
  • 16
1

Like what has been shown, use \". You need an escape character \ before writing quotation mark ".

apacheTextBox.Text = ("\"Header always set Public-Key-Pins ") + ("pin-sha256=\"base64+primary==\"; pin-sha256=\"base64+backup==\"; max-age=5184000; includeSubDomains\"");

Also, if you need the backslash, use double backslash \. The first one is the escape character, the second one the backslash.

apacheTextBox.Text = ("\"Header always set Public-Key-Pins ") + ("pin-sha256=\\\"base64+primary==\\\"; pin-sha256=\\\"base64+backup==\\\"; max-age=5184000; includeSubDomains\\\"");

The key here is to understand the escape character backslash .

Ian
  • 30,182
  • 19
  • 69
  • 107