C# Byte[] to Url Friendly String

前端 未结 2 569
难免孤独
难免孤独 2020-12-07 23:12

I\'m working on a quick captcha generator for a simple site I\'m putting together, and I\'m hoping to pass an encrypted key in the url of the page. I could probably do this

相关标签:
2条回答
  • 2020-12-07 23:30

    You're looking for HttpServerUtility.UrlTokenEncode and HttpServerUtility.UrlTokenDecode, in System.Web.

    They encode in base64, replacing the potentially dangerous '+' and '/' chars with '-' and '_' instead.

    MSDN documentation

    0 讨论(0)
  • 2020-12-07 23:30

    Have a look at System.BitConverter.ToString(myByteArray)

    Handy for one way encoding for things like hashes but as pointed out by ssg it's not very efficient. I wouldn't recommend it for large amounts of data.

    0 讨论(0)
提交回复
热议问题