Meir Schreiber
Meir Schreiber

Reputation: 142

c# Convert.ToBase64(String) with no pluses

I have a string which I need to convert to base64. The default convert

byte[] cipherbytes = rsa.Encrypt(plainbytes, false);

return Convert.ToBase64String(cipherbytes);

I get a string which has '+' like "pURT+TFG=" and is converted to a space when sent as a get, so I can't compare to the original.

Upvotes: 3

Views: 1057

Answers (1)

Patrick Hofman
Patrick Hofman

Reputation: 156978

First, it sounds as a bad idea to send large sets of bytes in the query string. Short byte arrays should be fine. Make sure if this is what you need.

Second, you have to URL encode your base64 encoded string, by calling HttpUtility.UrlEncode or WebUtility.UrlEncode (prefer the latter):

byte[] cipherbytes = rsa.Encrypt(plainbytes, false);

return WebUtility.UrlEncode(Convert.ToBase64String(cipherbytes));

Upvotes: 5

Related Questions