'react-native-sodium with PHP's sodium fails at crypto_box_seal_open()

Here's my encrypting flow:

  1. I'm creating a key-pair on my iOS device.
  2. I send to public key to the server (PHP) via Fetch
  3. I create a push-notification on the server and encrypts it with sodium_crypto_box_seal() and sends it sucessfully
  4. I receive the notification on my iOS device and try unsucessfully to decrypt the message with crypto_box_seal_open

React-native:

import Sodium from 'react-native-sodium';
let key_pair = { pk, sk } = await Sodium.crypto_box_keypair();
await sendToServer(pk);

-- PHP --

$msg = CloudMessage::fromArray(
  [ 'notification' => $notification,
         "apns" => [
            "payload" => [
                "aps" => [
                    "sound" => 'default',
                ],
            ],
        ]
    ]
);

sendMulticast( $message, $apn_tokens );

Then back in react-native I receive the push-notification

const incomingNotifiction = () => {
try {
   let note = JSON.parse(notification.notification.body.toString())
   note = btoa(note)
   let result = await Sodium.crypto_box_seal_open(note, public_key, private_key)
} catch(e) {
   console.log(e) // prints "FAILS HERE!" 
}
})

crypto_box_seal_open() from node_modules/react-native-sodium/iOS/RCTSodium.m


else if (crypto_box_seal_open(dm, [dc bytes], dc.length, [dpk bytes], [dsk bytes]) != 0)
    reject(ESODIUM,@"FAILS HERE!",nil);

Any idea why the decryption fails? Any help will be greatly appreciated. I've struggled for days now



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source