admin管理员组文章数量:1023758
I am trying to generate a simple test of crypto-js on node as follows:
'use strict';
var AES = require('crypto-js/aes');
var key = 'passPhrase';
var ecr = function(str)
{
return AES.encrypt(str, key);
};
var dcr = function(str)
{
return AES.decrypt(str, key);
};
console.log(dcr(ecr('hello world')));
// expected result is: hello world
The actual result is:
{ words: [ 1751477356, 1864398703, 1919706117, 84215045 ],
sigBytes: 11 }
What is the right usage?
I am trying to generate a simple test of crypto-js on node as follows:
'use strict';
var AES = require('crypto-js/aes');
var key = 'passPhrase';
var ecr = function(str)
{
return AES.encrypt(str, key);
};
var dcr = function(str)
{
return AES.decrypt(str, key);
};
console.log(dcr(ecr('hello world')));
// expected result is: hello world
The actual result is:
{ words: [ 1751477356, 1864398703, 1919706117, 84215045 ],
sigBytes: 11 }
What is the right usage?
Share Improve this question edited Jun 27, 2016 at 9:38 gevorg 5,0755 gold badges38 silver badges54 bronze badges asked Dec 23, 2013 at 7:20 user1028880user10288802 Answers
Reset to default 3I modified the code to deal any object:
'use strict';
var CryptoJS = require('crypto-js');
var key = 'pass phrase';
var ecr = function(obj)
{
return CryptoJS.AES.encrypt(JSON.stringify(obj), key);
};
var dcr = function(obj)
{
return JSON.parse(CryptoJS.AES.decrypt(obj, key)
.toString(CryptoJS.enc.Utf8));
};
var s = 'hello world';
console.log(dcr(ecr(s)));
var obj = {
id: 'ken',
key: 'password'
};
console.log(dcr(ecr(obj)));
Oh well.. Working Code:
'use strict';
var CryptoJS = require('crypto-js');
var key = 'pass phrase';
var ecr = function(str)
{
return CryptoJS.AES.encrypt(str, key);
};
var dcr = function(str)
{
return CryptoJS.AES.decrypt(str, key)
.toString(CryptoJS.enc.Utf8);
};
console.log(dcr(ecr('hello world')));
Result:
hello world
I am trying to generate a simple test of crypto-js on node as follows:
'use strict';
var AES = require('crypto-js/aes');
var key = 'passPhrase';
var ecr = function(str)
{
return AES.encrypt(str, key);
};
var dcr = function(str)
{
return AES.decrypt(str, key);
};
console.log(dcr(ecr('hello world')));
// expected result is: hello world
The actual result is:
{ words: [ 1751477356, 1864398703, 1919706117, 84215045 ],
sigBytes: 11 }
What is the right usage?
I am trying to generate a simple test of crypto-js on node as follows:
'use strict';
var AES = require('crypto-js/aes');
var key = 'passPhrase';
var ecr = function(str)
{
return AES.encrypt(str, key);
};
var dcr = function(str)
{
return AES.decrypt(str, key);
};
console.log(dcr(ecr('hello world')));
// expected result is: hello world
The actual result is:
{ words: [ 1751477356, 1864398703, 1919706117, 84215045 ],
sigBytes: 11 }
What is the right usage?
Share Improve this question edited Jun 27, 2016 at 9:38 gevorg 5,0755 gold badges38 silver badges54 bronze badges asked Dec 23, 2013 at 7:20 user1028880user10288802 Answers
Reset to default 3I modified the code to deal any object:
'use strict';
var CryptoJS = require('crypto-js');
var key = 'pass phrase';
var ecr = function(obj)
{
return CryptoJS.AES.encrypt(JSON.stringify(obj), key);
};
var dcr = function(obj)
{
return JSON.parse(CryptoJS.AES.decrypt(obj, key)
.toString(CryptoJS.enc.Utf8));
};
var s = 'hello world';
console.log(dcr(ecr(s)));
var obj = {
id: 'ken',
key: 'password'
};
console.log(dcr(ecr(obj)));
Oh well.. Working Code:
'use strict';
var CryptoJS = require('crypto-js');
var key = 'pass phrase';
var ecr = function(str)
{
return CryptoJS.AES.encrypt(str, key);
};
var dcr = function(str)
{
return CryptoJS.AES.decrypt(str, key)
.toString(CryptoJS.enc.Utf8);
};
console.log(dcr(ecr('hello world')));
Result:
hello world
本文标签: javascriptnode cryptojs AES encrypt gt decrypt usageStack Overflow
版权声明:本文标题:javascript - node crypto-js AES encrypt -> decrypt usage? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745592077a2157949.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论