question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

kms.decrypt is throwing TypeError: Not a buffer error

See original GitHub issue

When implementing kms.decrypt function and the the parameter ciphertextBlob obtained from kms.generateDataKey function is set as a value for the property CiphertextBlob on params object is showing the next error:

TypeError: Not a buffer at TypeError (native) at new Hmac (crypto.js:87:16) at Object.Hmac (crypto.js:85:12) at sign (/home/vagrant/node_modules/jwt-simple/lib/jwt.js:177:24) at verify (/home/vagrant/node_modules/jwt-simple/lib/jwt.js:162:27) at Object.jwt_decode [as decode] (/home/vagrant/node_modules/jwt-simple/lib/jwt.js:97:10) at /var/www/project/controllers/validation.js:81:28 at Response.<anonymous> (/var/www/project/services/aws/kms.js:48:5) at Request.<anonymous> (/home/vagrant/node_modules/aws-sdk/lib/request.js:355:18) at Request.callListeners (/home/vagrant/node_modules/aws-sdk/lib/sequential_executor.js:105:20)

This is the implementation:

function(ciphertextBlob, callback){

  console.log('is Buffer: ', Buffer.isBuffer(ciphertextBlob)); //true
  var blobString = ciphertextBlob.toString('base64');

  console.log('CiphertextBlob blobString : ', blobString); //posible string argument

  var params = {
    CiphertextBlob: ciphertextBlob
  };

 kms.decrypt(params, function(err, data) {
    if (err) 'Error on KMS decrypt: ' + err;
    callback(data);

  });

};

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alexosunascommented, Apr 11, 2016

@chrisradek It works fine, I just added the region on the constructor for your code:

var kms = new AWS.KMS({apiVersion: '2014-11-01', region: 'us-west-2'});

Thanks a lot for your help.

1reaction
chrisradekcommented, Apr 11, 2016

@alexosunas What version of the SDK are you using, and what environent? (node.js version or browser). Using the latest version of the SDK in node 0.12.x, this code is working for me:

var kms = new AWS.KMS({apiVersion: '2014-11-01'});
var generateDataKey = kms.generateDataKey({
    KeyId: 'alias/MyAlias',
    KeySpec: 'AES_256'
}).promise();

generateDataKey.then(function(data) {
    return kms.decrypt({
        CiphertextBlob: data.CiphertextBlob
    }).promise();
}).then(function(data) {
    console.log(data);
}).catch(function(err) {
    console.log(err);
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Decrypt text with AWS KMS in NodeJs - Stack Overflow
This code throws same error. So if you pass plain text that has never been encrypted before or has been encrypted with different...
Read more >
Resolve "InvalidCipherText" errors with AWS KMS
I'm using OpenSSL to import my key into AWS KMS, but I'm getting an "InvalidCiphertext" error. How can I fix this? Last updated:...
Read more >
Google Cloud KMS: The checksum in field ciphertext_crc32c ...
Coding example for the question Google Cloud KMS: The checksum in field ciphertext_crc32c did not match the data in field ciphertext-node.js.
Read more >
Bug listing with status RESOLVED with resolution TEST ...
Bug :233 - "Emacs segfaults when merged through the sandbox." status:RESOLVED resolution:TEST-REQUEST severity:critical · Bug:3888 - "yenta_socket module not ...
Read more >
Source: lib/mongo_client.js
Automatic encryption is not supported for operations on a database or view, and operations ... throw new TypeError('`connect` only accepts a callback'); ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found