新手需要 cryptojs 和 md5
Newbie needs with cryptojs and md5
我是 JavaScript 的新手。我想和 Rest API 一起玩。这需要创建用于身份验证的 X-Auth 密钥。
文档说:
The X-Auth-Key header should be constructed using the following
algorithm: md5(api_key + md5(url + X-Auth-User + api_key +
X-Auth-Expires)).
For example, consider a GET request to
https://<server_ip>/api/live_events/1?clean=true by the user 'admin'
with the api_key '1acpJN7oEDn3BDDYhQ' that expires on June 1, 2011
UTC. In this case the url parameter is '/live_events/1' and the
X-Auth-Expires value is '1306886400'. Thus the value of X-Auth-Key
should be computed as follows:
md5('1acpJN7oEDn3BDDYhQ' +
md5('/live_events/1'+'admin'+'1acpJN7oEDn3BDDYhQ'+'1306886400'))
=> md5('1acpJN7oEDn3BDDYhQ' + md5('/live_events/1admin1acpJN7oEDn3BDDYhQ1306886400'))
=> '180c88df8d0d4182385f6eb7e7045a42'
到目前为止我已经尝试用 CryptoJs 实现这个,但不幸的是我无法获得示例的值:
<script>
var md5xx = CryptoJS.MD5('/live_events/1admin1acpJN7oEDn3BDDYhQ1306886400')
var md5yy = CryptoJS.MD5(('1acpJN7oEDn3BDDYhQ') + String(md5xx));
console.log(md5yy.toString());
// => 17222238c238b7ac9f76ea8d0fe1e330
</script>
非常感谢您的帮助!提前致谢!
您获得的 md5 哈希 17222238c238b7ac9f76ea8d0fe1e330
是正确的。
给定的 180c88df8d0d4182385f6eb7e7045a42
反向查找示例给出了不同的 link /jobs/1admin1acpJN7oEDn3BDDYhQ1306886400
而不是 /live_events/1admin1acpJN7oEDn3BDDYhQ1306886400
.
您可以使用
进行交叉检查
https://md5.gromweb.com/?md5=180c88df8d0d4182385f6eb7e7045a42
和
https://md5.gromweb.com/?md5=a39ee4e3aa79939249cb6b5e7faead28
//the hash you actually expected
var md5xx = CryptoJS.MD5('/jobs/1admin1acpJN7oEDn3BDDYhQ1306886400')
var md5yy = CryptoJS.MD5(('1acpJN7oEDn3BDDYhQ') + String(md5xx));
console.log(md5yy.toString());
//correct hash according to the given link
var md5xx = CryptoJS.MD5('/live_events/1admin1acpJN7oEDn3BDDYhQ1306886400')
var md5yy = CryptoJS.MD5(('1acpJN7oEDn3BDDYhQ') + String(md5xx));
console.log(md5yy.toString());
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
我是 JavaScript 的新手。我想和 Rest API 一起玩。这需要创建用于身份验证的 X-Auth 密钥。
文档说:
The X-Auth-Key header should be constructed using the following algorithm: md5(api_key + md5(url + X-Auth-User + api_key + X-Auth-Expires)).
For example, consider a GET request to https://<server_ip>/api/live_events/1?clean=true by the user 'admin' with the api_key '1acpJN7oEDn3BDDYhQ' that expires on June 1, 2011 UTC. In this case the url parameter is '/live_events/1' and the X-Auth-Expires value is '1306886400'. Thus the value of X-Auth-Key should be computed as follows:
md5('1acpJN7oEDn3BDDYhQ' + md5('/live_events/1'+'admin'+'1acpJN7oEDn3BDDYhQ'+'1306886400')) => md5('1acpJN7oEDn3BDDYhQ' + md5('/live_events/1admin1acpJN7oEDn3BDDYhQ1306886400')) => '180c88df8d0d4182385f6eb7e7045a42'
到目前为止我已经尝试用 CryptoJs 实现这个,但不幸的是我无法获得示例的值:
<script>
var md5xx = CryptoJS.MD5('/live_events/1admin1acpJN7oEDn3BDDYhQ1306886400')
var md5yy = CryptoJS.MD5(('1acpJN7oEDn3BDDYhQ') + String(md5xx));
console.log(md5yy.toString());
// => 17222238c238b7ac9f76ea8d0fe1e330
</script>
非常感谢您的帮助!提前致谢!
您获得的 md5 哈希 17222238c238b7ac9f76ea8d0fe1e330
是正确的。
给定的 180c88df8d0d4182385f6eb7e7045a42
反向查找示例给出了不同的 link /jobs/1admin1acpJN7oEDn3BDDYhQ1306886400
而不是 /live_events/1admin1acpJN7oEDn3BDDYhQ1306886400
.
您可以使用
进行交叉检查
https://md5.gromweb.com/?md5=180c88df8d0d4182385f6eb7e7045a42
和
https://md5.gromweb.com/?md5=a39ee4e3aa79939249cb6b5e7faead28
//the hash you actually expected
var md5xx = CryptoJS.MD5('/jobs/1admin1acpJN7oEDn3BDDYhQ1306886400')
var md5yy = CryptoJS.MD5(('1acpJN7oEDn3BDDYhQ') + String(md5xx));
console.log(md5yy.toString());
//correct hash according to the given link
var md5xx = CryptoJS.MD5('/live_events/1admin1acpJN7oEDn3BDDYhQ1306886400')
var md5yy = CryptoJS.MD5(('1acpJN7oEDn3BDDYhQ') + String(md5xx));
console.log(md5yy.toString());
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>