RSA 密码学 JavaScript
我正在尝试为我创建的 RESTful Web 服务构建用户登录/身份验证客户端。 然而,在尝试使用身份验证 API 的可用 JAX-RS 设置身份验证时,我遇到了一些麻烦,并决定更改方法。现在,我实际上想做的是: 该网页向 uri(用户/登录名)发送一个 ajax POST 请求,其中包含他的电子邮件和密码,并用“:”符号分隔。然后,该消息正文将在客户端中使用一些 JavaScript 库使用 RSA 算法进行加密,并在服务器端进行解密。
问题是:我使用 Java 生成 PublicKey,它们存储为 base64 字符串,并使用 X509 填充进行编码。
如何仅使用 JavaScript 来解码这个代表公钥的编码字符串,并实际使用它来加密某些文本?
提前致谢!
I'm trying to build an user login/authentication client for a RESTful webservice created by me.
However, while trying to setup authentication using the authentication API's available JAX-RS, I had some troubles and decided to change the approach. Now, what I'm actually trying to do is:
The webpage sends an ajax POST request to an uri (user/login) contained with his email and his password separated by an ":" symbol. This message body will then be encrypted using the RSA algorithm in the client using some JavaScript lib and decrypted on the server side.
The problem is: I used Java to generate the PublicKey, and they are stored as an base64 string, encoded using X509 padding.
How can I decode this encoded string, which represents the Public Key, using only JavaScript, and actually use it to encrypt some text?
thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么只想加密消息正文?只需通过 SSL 发出 AJAX 请求 - 您的整个传输都会被加密。
这只需要对代码进行最小的更改(将
https
放在 url 前面),并且您不必担心 JavaScript 中的加密。Why do you want to encrypt just message body? Just make your AJAX request over SSL - your whole transmission will be encrypted.
This will require only minimal changes in your code (put
https
in front of url) and you don't have to worry about encryption in javascript.一旦我使用了 JQuery 插件来解码 Base64 字符串。
更多信息请点击这里。 http://plugins.jquery.com/project/base64
Once i've used a JQuery plugin in order to decode a base64 string.
More info here. http://plugins.jquery.com/project/base64