I need to Percent Encoding for my Url and Pararmeters. I am using UrlEncode, it works fine but it returns lower case but not the upper case. How can I have Uppercase for the encoded characters?
var pEncodeUrl = HttpUtility.UrlEncode(url);
it gives like 'https%3a%2f%2fapi.test.com' But i Need like 'https%3A%2F%2Fapi.test.com'
If I would var pEncodeUrl = HttpUtility.UrlEncode(url).ToUpper(), It gives thw whole URL as Upper case which I dont need.
The percent-encoded representations must be capitalized in the base string which is passed into the HMAC-SHA1 function. In other words, “:” must be encoded as "%3A" instead of "%3a".
You might have to resort to calling UrlEncode() and then ToUpper() on just the part you want/need uppercase, and just UrlEncode() on the rest and then concatenate the two together.
I don't understand what you mean. I am using it right now and do not have this issue. I don't know what you mean by MUST. It's just an encryption technique. Doesn't matter what you pass it. As long as the client and server do the same thing, it works.
... I don't know what you mean by MUST. It's just an encryption technique. Doesn't matter what you pass it. As long as the client and server do the same thing, it works.
Right, I suspect this is the issue. Perhaps he's sending this off to some other app and it's expecting the casing the way he described.
Loop over it with a regex and do replacements. Only thing I got. I don't know of any "upper case only url encoding" built into .net. You, and the person you're dealing with, should probably be SHA'ing the pre-encoded value to avoid these problems.
%[a-zA-Z0-9]{2}
Match that and loop over doing replacements to the upper case version.
nayanancha
Member
158 Points
244 Posts
How to have the Uppercase Encoding for the string?
Apr 26, 2012 03:29 PM|LINK
I need to Percent Encoding for my Url and Pararmeters. I am using UrlEncode, it works fine but it returns lower case but not the upper case. How can I have Uppercase for the encoded characters?
var pEncodeUrl = HttpUtility.UrlEncode(url);
it gives like 'https%3a%2f%2fapi.test.com' But i Need like 'https%3A%2F%2Fapi.test.com'
If I would var pEncodeUrl = HttpUtility.UrlEncode(url).ToUpper(), It gives thw whole URL as Upper case which I dont need.
How can I get it fixed?
Thanks,
digitalpacma...
Member
183 Points
148 Posts
Re: How to have the Uppercase Encoding for the string?
Apr 26, 2012 04:11 PM|LINK
Why do you need it upper case?
nayanancha
Member
158 Points
244 Posts
Re: How to have the Uppercase Encoding for the string?
Apr 26, 2012 04:13 PM|LINK
The percent-encoded representations must be capitalized in the base string which is passed into the HMAC-SHA1 function. In other words, “:” must be encoded as "%3A" instead of "%3a".
BrockAllen
All-Star
27564 Points
4912 Posts
MVP
Re: How to have the Uppercase Encoding for the string?
Apr 26, 2012 04:16 PM|LINK
You might have to resort to calling UrlEncode() and then ToUpper() on just the part you want/need uppercase, and just UrlEncode() on the rest and then concatenate the two together.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
digitalpacma...
Member
183 Points
148 Posts
Re: How to have the Uppercase Encoding for the string?
Apr 26, 2012 04:27 PM|LINK
I don't understand what you mean. I am using it right now and do not have this issue. I don't know what you mean by MUST. It's just an encryption technique. Doesn't matter what you pass it. As long as the client and server do the same thing, it works.
string userkey = _users[token.PublicKey]; byte[] secretBytes = ASCIIEncoding.ASCII.GetBytes(userkey); HMACSHA256 hmac = new HMACSHA256(secretBytes); byte[] dataBytes = ASCIIEncoding.ASCII.GetBytes(uri + token.Timestamp); byte[] computedHash = hmac.ComputeHash(dataBytes); string computedHashString = Convert.ToBase64String(computedHash); return computedHashString.Equals(token.Signature);BrockAllen
All-Star
27564 Points
4912 Posts
MVP
Re: How to have the Uppercase Encoding for the string?
Apr 26, 2012 05:05 PM|LINK
Right, I suspect this is the issue. Perhaps he's sending this off to some other app and it's expecting the casing the way he described.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
digitalpacma...
Member
183 Points
148 Posts
Re: How to have the Uppercase Encoding for the string?
Apr 26, 2012 05:48 PM|LINK
Loop over it with a regex and do replacements. Only thing I got. I don't know of any "upper case only url encoding" built into .net. You, and the person you're dealing with, should probably be SHA'ing the pre-encoded value to avoid these problems.
%[a-zA-Z0-9]{2}
Match that and loop over doing replacements to the upper case version.
digitalpacma...
Member
183 Points
148 Posts
Re: How to have the Uppercase Encoding for the string?
Apr 26, 2012 05:50 PM|LINK
split("%")
for (i = 1; i < length; i += 2)
items[i] = items[i].ToUpper()
.join("%")
nayanancha
Member
158 Points
244 Posts
Re: How to have the Uppercase Encoding for the string?
Apr 26, 2012 06:07 PM|LINK
Thanks, I got it through like below
digitalpacma...
Member
183 Points
148 Posts
Re: How to have the Uppercase Encoding for the string?
Apr 26, 2012 07:22 PM|LINK
The split ,method is probably like 10x faster. but coo.