Skip to content

Commit

Permalink
fix: pubnub.decrypt() function to return correct data format (#342)
Browse files Browse the repository at this point in the history
* fix: pubnub.decrypt() function to return correct data format

* PubNub SDK v7.4.1 release.

---------

Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com>
  • Loading branch information
mohitpubnub and pubnub-release-bot authored Oct 17, 2023
1 parent fb6cd04 commit 3eca7d2
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 13 deletions.
11 changes: 8 additions & 3 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
---
changelog:
- date: 2023-10-17
version: v7.4.1
changes:
- type: bug
text: "Fixes issue of `pubnub.decrypt()` returning wrong data format."
- date: 2023-10-16
version: v7.4.0
changes:
Expand Down Expand Up @@ -902,7 +907,7 @@ supported-platforms:
- 'Ubuntu 14.04 and up'
- 'Windows 7 and up'
version: 'Pubnub Javascript for Node'
version: '7.4.0'
version: '7.4.1'
sdks:
- full-name: PubNub Javascript SDK
short-name: Javascript
Expand All @@ -918,7 +923,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.4.0.zip
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.4.1.zip
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down Expand Up @@ -1589,7 +1594,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/releases/download/v7.4.0/pubnub.7.4.0.js
location: https://github.com/pubnub/javascript/releases/download/v7.4.1/pubnub.7.4.1.js
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v7.4.1
October 17 2023

#### Fixed
- Fixes issue of `pubnub.decrypt()` returning wrong data format.

## v7.4.0
October 16 2023

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2
npm install pubnub
```
* or download one of our builds from our CDN:
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.4.0.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.4.0.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.4.1.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.4.1.min.js
2. Configure your keys:
Expand Down
4 changes: 2 additions & 2 deletions dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@
return this;
};
default_1.prototype.getVersion = function () {
return '7.4.0';
return '7.4.1';
};
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
this._PNSDKSuffix[name] = suffix;
Expand Down Expand Up @@ -7843,7 +7843,7 @@
this.decrypt = function (data, key) {
if (typeof key === 'undefined' && cryptoModule) {
var decrypted = modules.cryptoModule.decrypt(data);
return decrypted instanceof ArrayBuffer ? encode$1(decrypted) : decrypted;
return decrypted instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decrypted)) : decrypted;
}
else {
return crypto.decrypt(data, key);
Expand Down
2 changes: 1 addition & 1 deletion dist/web/pubnub.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/core/components/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ var default_1 = /** @class */ (function () {
return this;
};
default_1.prototype.getVersion = function () {
return '7.4.0';
return '7.4.1';
};
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
this._PNSDKSuffix[name] = suffix;
Expand Down
2 changes: 1 addition & 1 deletion lib/core/pubnub-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ var default_1 = /** @class */ (function () {
this.decrypt = function (data, key) {
if (typeof key === 'undefined' && cryptoModule) {
var decrypted = modules.cryptoModule.decrypt(data);
return decrypted instanceof ArrayBuffer ? (0, base64_codec_1.encode)(decrypted) : decrypted;
return decrypted instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decrypted)) : decrypted;
}
else {
return crypto.decrypt(data, key);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pubnub",
"version": "7.4.0",
"version": "7.4.1",
"author": "PubNub <support@pubnub.com>",
"description": "Publish & Subscribe Real-time Messaging with PubNub",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export default class {
}

getVersion() {
return '7.4.0';
return '7.4.1';
}

_addPnsdkSuffix(name, suffix) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/pubnub-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ export default class {
this.decrypt = function (data, key) {
if (typeof key === 'undefined' && cryptoModule) {
const decrypted = modules.cryptoModule.decrypt(data);
return decrypted instanceof ArrayBuffer ? encode(decrypted) : decrypted;
return decrypted instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decrypted)) : decrypted;
} else {
return crypto.decrypt(data, key);
}
Expand Down
22 changes: 22 additions & 0 deletions test/integration/components/crypto.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,26 @@ describe('components/crypto useRandomIVs', () => {

expect(decrypted).to.deep.equal(data);
});

it('should be able to encrypt and decrypt a message with CryptoModule', () => {
const pubnub = new PubNub({
subscribeKey: 'demo-36',
publishKey: 'demo-36',
useRandomIVs: true,
cryptoModule: PubNub.CryptoModule.aesCbcCryptoModule({
cipherKey: 'abcd'
}),
uuid: 'myUUID',
});
const data = {
message:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
};
const plaintext = JSON.stringify(data);
const ciphertext = pubnub.encrypt(plaintext);

const decrypted = pubnub.decrypt(ciphertext);

expect(decrypted).to.deep.equal(data);
});
});

0 comments on commit 3eca7d2

Please sign in to comment.