Analytics

2010年5月27日 星期四

[Web]URL Encoding 簡單的介紹

昨天客戶那邊給了一個bug,問題是說"加密後的資料"傳到WebService時,解密的時候會出現錯誤,導致程式結果錯誤


為了這個問題,我仔細的看了自己的WebService的解密方式,也確認了與客戶當初所說的一致


但客戶給了SampleCode裡的加解密方式,當初是原封不動的加入程式再呼叫而已...問題出在哪?


為此問題找了一下解答,才發現,
是客戶"加密後的資料",雖用同一支SamlpeCode加密而成,但並未使用HttpUtility.HtmlEncode(),導致好死不死的,加密後的資料有20%3d%3d,
而在WebService裡又使用HttpUtility.HtmlDecode()先轉譯,導致20的部份轉譯成"空白",
傳入SamlpeCode裡解密時,造成64bit長度不符的Exception
(好笑的是我花了兩個小時才發現,之前用debug的方式在找,都看不出來,
直到貼到notepad上才看到~昏倒)

為此找個一些資料做整理,原始出處於URL Encoding


"Reserved characters"
    Why:URLs use some characters for special use in defining their syntax. When these characters are not used in their special role inside a URL, they need to be encoded.
Characters:
CharacterCode
Points
(Hex)
Code
Points
(Dec)
 Dollar ("$")
 Ampersand ("&")
 Plus ("+")
 Comma (",")
 Forward slash/Virgule ("/")
 Colon (":")
 Semi-colon (";")
 Equals ("=")
 Question mark ("?")
 'At' symbol ("@")
24
26
2B
2C
2F
3A
3B
3D
3F
40
36
38
43
44
47
58
59
61
63
64
"Unsafe characters"
    Why:Some characters present the possibility of being misunderstood within URLs for various reasons. These characters should also always be encoded.
Characters:
CharacterCode
Points
(Hex)
Code
Points
(Dec)
Why encode?
Space2032Significant sequences of spaces may be lost in some uses (especially multiple spaces)
Quotation marks
'Less Than' symbol ("<")
'Greater Than' symbol (">")
22
3C
3E
34
60
62
These characters are often used to delimit URLs in plain text.
'Pound' character ("#")2335This is used in URLs to indicate where a fragment identifier (bookmarks/anchors in HTML) begins.
Percent character ("%")2537This is used to URL encode/escape other characters, so it should itself also be encoded.
Misc. characters:
   Left Curly Brace ("{")
   Right Curly Brace ("}")
   Vertical Bar/Pipe ("|")
   Backslash ("\")
   Caret ("^")
   Tilde ("~")
   Left Square Bracket ("[")
   Right Square Bracket ("]")
   Grave Accent ("`")

7B
7D
7C
5C
5E
7E
5B
5D
60

123
125
124
92
94
126
91
93
96
Some systems can possibly modify these characters.


看到了嗎?就是因為出現"20"導致Decode時,將之轉成"空白"~真是冤忘阿!!

哈哈~要來去跟客戶請錢了,竟然害我做白工~~

以上

沒有留言:

熱門文章