Reputation: 7004
I need to generate HEX encoded CMAC-AES digest using Node.JS. I have found library from GitHub. I want to know how to call it? This is the part I want to do it in node.js. I want to pass key
and message
.
I imported this library into my node.js project. I want to know how to call this method aesCmac
.
My index.js
var express = require('express');
var querystring = require('querystring');
var http = require('http');
var aesCmac = require('./lib/aes-cmac.js');
var app = express();
app.get('/aesCmac', aesCmac.aesCmac('xxxxxxxx' ,'LSCourse|0xxxxxxxx|103xxxxxxxx|xxxxx|[email protected]|2014-11-11T09:29:04Z'));
app.configure(function () {
app.use(express.logger('dev')); /* 'default', 'short', 'tiny', 'dev' */
app.use(express.bodyParser());
});
app.listen(80);
I got this error:
F:\NODE.JS\node-aes-cmac-master>node index.js
node-crypto : Invalid key length 32
crypto.js:315
this._binding.initiv(cipher, toBuf(key), toBuf(iv));
^
Error: error:0607A082:digital envelope routines:EVP_CIPHER_CTX_set_key_length:invalid key length
at new Cipheriv (crypto.js:315:17)
at Object.Cipheriv (crypto.js:313:12)
at aes128 (F:\NODE.JS\node-aes-cmac-master\lib\aes-cmac.js:25:23)
at Object.exports.generateSubkeys (F:\NODE.JS\node-aes-cmac-master\lib\aes-cmac.js:9:11)
at Object.exports.aesCmac (F:\NODE.JS\node-aes-cmac-master\lib\aes-cmac.js:32:25)
at Object.<anonymous> (F:\NODE.JS\node-aes-cmac-master\index.js:9:29)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
I am new to Node js.
Upvotes: 0
Views: 626
Reputation: 61952
The test file shows how it can be used. You can't simply plug aesCmac.aesCmac
into app.get
. You need to handle the request and send the response.
// some hex encoded 512bit key
var key = new Buffer('2b7e151628aed2a6abf7158809cf4f3c', 'hex');
var msg = new Buffer('LSCourse|0xxxxxxxx|103xxxxxxxx|xxxxx|[email protected]|2014-11-11T09:29:04Z');
app.get('/aesCmac', function(req, res){
var result = aesCmac.aesCmac(key, msg);
res.status(200).send(result.toString('hex'));
});
Upvotes: 2