高效、URL 安全的双向文本编码
我觉得我最终不得不做很多这样的事情。我有一些数据块,比如要在页面上显示的一系列产品。我的网址如下所示:
http://mywebsite.com/displayproducts/? p=product_id1,product_id2,product_id3,product_id4
我想对该产品列表进行匿名化处理,使其成为不可读的网址。它不必是加密安全的,但我只是不希望用户能够直接从 URL 读取数据。
我想要一些看起来“随机”的东西,例如:
http://mywebsite.com/displayproducts/ ?p=X298Xjijdf088DFhj781hJhk1
...但解码为Product_id1,product_id2,product_id3,product_id4
通常,我只会压缩字符串,然后对其进行 Base64 编码,但我想知道是否有更聪明的方法。我想避免在后端保留状态或想出一些方案来为每个产品 ID 分配整数值。我正在寻找通用的文本->文本解决方案,无论数据的性质如何。
I feel like I end up having to do this a lot. I've got some chunk of data, say a series of products to display on a page. My URL looks something like this:
http://mywebsite.com/displayproducts/?p=product_id1,product_id2,product_id3,product_id4
I want to anonymize that product list so it's not a readable URL. It doesn't have to be crypto-safe, but I just don't want users to be able to read the data straight from the URL.
I'd like something that looks "random", a la:
http://mywebsite.com/displayproducts/?p=X298Xjijdf088DFhj781hJhk1
...but decodes to product_id1,product_id2,product_id3,product_id4
Typically, I'll just compress the string and then base64 encode it, but I'm wondering if there's a smarter way. I want to avoid keeping state in the backend or coming up with some scheme to assign integer values to each product id. I'm looking for a general text->text solution, regardless of the nature of the data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论