Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The response payload is returning an undefined body #25

Closed
zakipatel opened this issue May 20, 2021 · 2 comments
Closed

The response payload is returning an undefined body #25

zakipatel opened this issue May 20, 2021 · 2 comments

Comments

@zakipatel
Copy link

The response payload is returning a body that is undefined.

In the code snippet, after calling fle.ecrypt(), when i log the variable to the console:

let responsePayload = fle.encrypt("/resource1", payload);
console.log(responsePayload)

it displays the following:

``` { header: { path: { to: [Object] } }, body: undefined } ````

Below is the code - any help is much appreciated.thanks !

const clientEncryption = require('mastercard-client-encryption');

const config = {
paths: [
{
path: "/resource",
toEncrypt: [
{
/* path to element to be encrypted in request json body /
element: "path.to.foo",
/
path to object where to store encryption fields in request json body /
obj: "path.to.encryptedFoo"
}],
toDecrypt: [
{
/
path to element where to store decrypted fields in response object /
element: "path.to.encryptedFoo",
/
path to object with encryption fields */
obj: "path.to.foo"
}
]
}
],
ivFieldName: 'iv',
encryptedKeyFieldName: 'encryptedKey',
encryptedValueFieldName: 'encryptedData',
dataEncoding: 'hex',
encryptionCertificate: './certificate.pem',
publicKeyFingerprintType: "certificate",
oaepPaddingDigestAlgorithm: 'SHA-256'
// privateKey: '',
// ivHeaderName: "x-iv",
// EncryptedKeyHeaderName: "x-encrypted-key"

};

const payload =
{
"path": {
"to": {
"foo": {
"sensitive": "this is a secret!"
}
}
}
};

const fle = new clientEncryption.FieldLevelEncryption(config);
console.log(fle)

let responsePayload = fle.encrypt("/resource1", payload);
console.log(responsePayload)

@jaaufauvre
Copy link
Member

@zakipatel,

It seems there is a parameter mismatch.

The encrypt function accepts 3 parameters: encrypt(endpoint, header, body) (see README.md).

Thus, you must pass:

  • endpoint first
  • header second (it can be an empty associative array)
  • payload last

Best regards,

@zakipatel
Copy link
Author

Thanks, that fixed it.

let responsePayload = fle.encrypt("/resource1", [], payload);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants