Skip to content

Commit 3eca7d2

Browse files
fix: pubnub.decrypt() function to return correct data format (#342)
* fix: pubnub.decrypt() function to return correct data format * PubNub SDK v7.4.1 release. --------- Co-authored-by: PubNub Release Bot <[email protected]>
1 parent fb6cd04 commit 3eca7d2

File tree

11 files changed

+46
-13
lines changed

11 files changed

+46
-13
lines changed

.pubnub.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
22
changelog:
3+
- date: 2023-10-17
4+
version: v7.4.1
5+
changes:
6+
- type: bug
7+
text: "Fixes issue of `pubnub.decrypt()` returning wrong data format."
38
- date: 2023-10-16
49
version: v7.4.0
510
changes:
@@ -902,7 +907,7 @@ supported-platforms:
902907
- 'Ubuntu 14.04 and up'
903908
- 'Windows 7 and up'
904909
version: 'Pubnub Javascript for Node'
905-
version: '7.4.0'
910+
version: '7.4.1'
906911
sdks:
907912
- full-name: PubNub Javascript SDK
908913
short-name: Javascript
@@ -918,7 +923,7 @@ sdks:
918923
- distribution-type: source
919924
distribution-repository: GitHub release
920925
package-name: pubnub.js
921-
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.4.0.zip
926+
location: https://github.com/pubnub/javascript/archive/refs/tags/v7.4.1.zip
922927
requires:
923928
- name: 'agentkeepalive'
924929
min-version: '3.5.2'
@@ -1589,7 +1594,7 @@ sdks:
15891594
- distribution-type: library
15901595
distribution-repository: GitHub release
15911596
package-name: pubnub.js
1592-
location: https://github.com/pubnub/javascript/releases/download/v7.4.0/pubnub.7.4.0.js
1597+
location: https://github.com/pubnub/javascript/releases/download/v7.4.1/pubnub.7.4.1.js
15931598
requires:
15941599
- name: 'agentkeepalive'
15951600
min-version: '3.5.2'

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v7.4.1
2+
October 17 2023
3+
4+
#### Fixed
5+
- Fixes issue of `pubnub.decrypt()` returning wrong data format.
6+
17
## v7.4.0
28
October 16 2023
39

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2
2828
npm install pubnub
2929
```
3030
* or download one of our builds from our CDN:
31-
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.4.0.js
32-
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.4.0.min.js
31+
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.4.1.js
32+
* https://cdn.pubnub.com/sdk/javascript/pubnub.7.4.1.min.js
3333
3434
2. Configure your keys:
3535

dist/web/pubnub.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@
791791
return this;
792792
};
793793
default_1.prototype.getVersion = function () {
794-
return '7.4.0';
794+
return '7.4.1';
795795
};
796796
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
797797
this._PNSDKSuffix[name] = suffix;
@@ -7843,7 +7843,7 @@
78437843
this.decrypt = function (data, key) {
78447844
if (typeof key === 'undefined' && cryptoModule) {
78457845
var decrypted = modules.cryptoModule.decrypt(data);
7846-
return decrypted instanceof ArrayBuffer ? encode$1(decrypted) : decrypted;
7846+
return decrypted instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decrypted)) : decrypted;
78477847
}
78487848
else {
78497849
return crypto.decrypt(data, key);

dist/web/pubnub.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/components/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ var default_1 = /** @class */ (function () {
177177
return this;
178178
};
179179
default_1.prototype.getVersion = function () {
180-
return '7.4.0';
180+
return '7.4.1';
181181
};
182182
default_1.prototype._addPnsdkSuffix = function (name, suffix) {
183183
this._PNSDKSuffix[name] = suffix;

lib/core/pubnub-common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ var default_1 = /** @class */ (function () {
500500
this.decrypt = function (data, key) {
501501
if (typeof key === 'undefined' && cryptoModule) {
502502
var decrypted = modules.cryptoModule.decrypt(data);
503-
return decrypted instanceof ArrayBuffer ? (0, base64_codec_1.encode)(decrypted) : decrypted;
503+
return decrypted instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decrypted)) : decrypted;
504504
}
505505
else {
506506
return crypto.decrypt(data, key);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pubnub",
3-
"version": "7.4.0",
3+
"version": "7.4.1",
44
"author": "PubNub <[email protected]>",
55
"description": "Publish & Subscribe Real-time Messaging with PubNub",
66
"scripts": {

src/core/components/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export default class {
350350
}
351351

352352
getVersion() {
353-
return '7.4.0';
353+
return '7.4.1';
354354
}
355355

356356
_addPnsdkSuffix(name, suffix) {

src/core/pubnub-common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ export default class {
691691
this.decrypt = function (data, key) {
692692
if (typeof key === 'undefined' && cryptoModule) {
693693
const decrypted = modules.cryptoModule.decrypt(data);
694-
return decrypted instanceof ArrayBuffer ? encode(decrypted) : decrypted;
694+
return decrypted instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decrypted)) : decrypted;
695695
} else {
696696
return crypto.decrypt(data, key);
697697
}

test/integration/components/crypto.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,26 @@ describe('components/crypto useRandomIVs', () => {
2323

2424
expect(decrypted).to.deep.equal(data);
2525
});
26+
27+
it('should be able to encrypt and decrypt a message with CryptoModule', () => {
28+
const pubnub = new PubNub({
29+
subscribeKey: 'demo-36',
30+
publishKey: 'demo-36',
31+
useRandomIVs: true,
32+
cryptoModule: PubNub.CryptoModule.aesCbcCryptoModule({
33+
cipherKey: 'abcd'
34+
}),
35+
uuid: 'myUUID',
36+
});
37+
const data = {
38+
message:
39+
'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.',
40+
};
41+
const plaintext = JSON.stringify(data);
42+
const ciphertext = pubnub.encrypt(plaintext);
43+
44+
const decrypted = pubnub.decrypt(ciphertext);
45+
46+
expect(decrypted).to.deep.equal(data);
47+
});
2648
});

0 commit comments

Comments
 (0)