admin管理员组文章数量:1389783
There is a lot resources about how to secure REST API access, but this not what I am looking for. I am going to use provided REST API with Basic Authentication (and this cannot be changed easily :( ).
Obviously I can go with:
var requestOptions = {
hostname: "rest.api.url",
path: "/path/",
auth: "username:password"
};
var req = http.request(requestOptions, function (res) {
// some code here
});
Is there a way to not provide password in plain text in the script?
There is a lot resources about how to secure REST API access, but this not what I am looking for. I am going to use provided REST API with Basic Authentication (and this cannot be changed easily :( ).
Obviously I can go with:
var requestOptions = {
hostname: "rest.api.url.",
path: "/path/",
auth: "username:password"
};
var req = http.request(requestOptions, function (res) {
// some code here
});
Is there a way to not provide password in plain text in the script?
Share Improve this question asked May 12, 2015 at 0:48 Przemek SechPrzemek Sech 471 gold badge1 silver badge7 bronze badges2 Answers
Reset to default 3Is there a way to not provide password in plain text in the [JavaScript]?
Client-side JavaScript will always be vulnerable to tampering and modification, including reversing any "encrypted" passwords you store in the client-side script. You can obfuscate your code all you like, but if the password is present in any form in your client script, it is accessible.
I am going to use a provided REST API with Basic Authentication (and this cannot be changed easily
Since you can't change the REST API to use something like tokens or SSL, one solution that es to mind is to have an intermediary between your server and the REST API which does use SSL. Communicate securely with some server-side script on your server, and have this script proxy the requests and responses from the REST API.
Resources:
- How to encrypt data in javascript and decrypt in php?
- Secure munication between JavaScript and a Web service in PHP
- How to secure the password while it being sent using AJAX?
You can encode it with whatever encryption you like, however your encryption technique will still exist on the client side. The proper thing to do here is to setup a SSL certificate so that your requests bee encrypted with the certificate.
Furthermore, to reduce the need to send passwords around you may want to look at using some sort of token based authentication.
本文标签: javascriptHow to Encrypt password for REST API authenticationStack Overflow
版权声明:本文标题:javascript - How to Encrypt password for REST API authentication - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744623042a2616143.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论