Search code examples
pubnub

Does Pubnub encrypt messages if the sender and receiver use different Pubnub version?


I have Pubnub v7 (latest) in my website and v3.16.5 on my mobile app (I can't upgrade the mobile version). The problem is when I send a message from my website I can see it in its original form but the mobile application can't because he receive it encrypted as this image show (I get this output when I log the message payload), the same thing happen to the mobile version, user can see his message but I can't because it is encrypted!

Also I'm not sure if this is encryption or this is due to the fact that these are two different versions, but I'm sure that my configuration doesn't have any encryption because everything works fine when I downgraded to pubnub v3.16.5 on my website!

enter image description here

These are my configuration, I removed some codes to reduce the question size please tell me if you need something more.

function CreatePubNubInstance(userId: string) {
    return new PubNub({
        publishKey: "pubNubPublishKey",
        subscribeKey: "pubNubSubscribeKey",
        secret_key: "pubNubSecretKey",
        cipher_key: "pubNubCipherKey",
        userId,
    });
}

    const pubnub = PubnubFactory.CreatePubNubInstance(userId);
    pubnub.subscribe({channels: [state.ChannelName]}
    pubnub.addListener({
      // Messages
      message: function (m: any) {
        const pubTT = m.timetoken; // Publish timetoken
        const msg = m.message; // Message payload
        handleMessage(msg, pubTT);
      }
    })
    pubnub.fetchMessages(
        {
            channels: [state.ChannelName],
        },
        (status: any, response: any) => {
            const { channels } = response;
            const history = channels[state.ChannelName as string].map((message: any) => message.message);
        console.log(history); // This is the output you see in the image
        }
    );
    const res = await pubnub.publish({
        message: msg,
        channel: state.ChannelName,
        storeInHistory: true,
    });

Thanks.


Solution

  • Short answer - the mobile app just needs to set randomIV to false.

    Or you can upgrade the web app to use latest PubNub SDK and leave the randomIV setting to true.

    var pubnub = new PubNub({
        subscribeKey: "mySubscribeKey",
        publishKey: "myPublishKey",
        cipherKey: "myCipherKey",
        authKey: "myAuthKey",
        userId: "myUniqueUserId",
        useRandomIVs: true // true is default
    });