电子邮件 Rails 中的加密查询字符串

发布于 2024-12-22 18:05:39 字数 1272 浏览 5 评论 0原文

我的应用程序发送一封包含 URL 的电子邮件。该 url 包含已加密的查询字符串属性。我 CGI 转义了加密值,以便使用像 + * 这样的符号。等都逃脱了。转义的 URL 按预期出现在电子邮件中,但当我们单击链接时,加密的值将被解密。

例如邮件中的url如下 http://development.com/activate/snJAmJxkMo3WZ1sG27Aq?album_id=2&email=5M%2BjE1G6UB26tw/Ah%2Bzr1%2BJSSxeAoP6j&owner_id=4

email=5M%2BjE1G6UB26tw/Ah%2Bzr1%2BJSSxeAoP6j

当我们单击此链接时,浏览器中的 url 显示为 http://development.com/activate/snJAmJxkMo3WZ1sG27Aq?album_id=2&email=5M+jE1G6UB26tw/Ah+zr1+JSSxeAoP6j&owner_id=4

email=5M+jE1G6UB26tw/Ah+zr1+JSSxeAoP6j

+ 替换为空格。因此 params[:email] = 5M jE1G6UB26tw/Ah zr1 JSSxeAoP6j

这给了我一个 404。

有什么办法可以避免这种情况。如何使浏览器中的网址也显示为

http://development.com/activate/snJAmJxkMo3WZ1sG27Aq?album_id=2&email=5M%2BjE1G6UB26tw/Ah%2Bzr1%2BJSSxeAoP6j&owner_id=4

在浏览器中?

My app sends out an email with a URL in it. The url contains a query string attribute that is encrypted. I CGI escaped the encrypted value so that symbols like + * . etc are escaped. The escaped URL appears in the email as expected, but when we click on the link, the encrypted values are decrypted.

For Example, the url in the email is as follows
http://development.com/activate/snJAmJxkMo3WZ1sG27Aq?album_id=2&email=5M%2BjE1G6UB26tw/Ah%2Bzr1%2BJSSxeAoP6j&owner_id=4

email=5M%2BjE1G6UB26tw/Ah%2Bzr1%2BJSSxeAoP6j

when we click on this link the url in the browser appears as
http://development.com/activate/snJAmJxkMo3WZ1sG27Aq?album_id=2&email=5M+jE1G6UB26tw/Ah+zr1+JSSxeAoP6j&owner_id=4

email=5M+jE1G6UB26tw/Ah+zr1+JSSxeAoP6j

The + is substituted with space. As a result
params[:email] = 5M jE1G6UB26tw/Ah zr1 JSSxeAoP6j

which gives me a 404.

Is there any way I can avoid this situation. How can I make the url in the browser also appear as

http://development.com/activate/snJAmJxkMo3WZ1sG27Aq?album_id=2&email=5M%2BjE1G6UB26tw/Ah%2Bzr1%2BJSSxeAoP6j&owner_id=4

in the browser?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耀眼的星火 2024-12-29 18:05:39

为了避免这种情况,我对电子邮件属性进行了十六进制编码,使其仅包含字母和数字。使用这些是十六进制编码和解码的方法。

convert string2hex:
def hexdigest_to_string(string)
 string.unpack('U'*string.length).collect {|x| x.to_s 16}.join
end

convert hex2string
def hexdigest_to_digest(hex)
 hex.unpack('a2'*(hex.size/2)).collect {|i| i.hex.chr }.join
end

In order to avoid this situation I Hex encoded the email attribute so that the it contains only alphabets and numbers. Used these are the methods to Hex encode and decode.

convert string2hex:
def hexdigest_to_string(string)
 string.unpack('U'*string.length).collect {|x| x.to_s 16}.join
end

convert hex2string
def hexdigest_to_digest(hex)
 hex.unpack('a2'*(hex.size/2)).collect {|i| i.hex.chr }.join
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文