React-native-sodium 与 PHP 的钠在 crypto_box_seal_open() 处失败

发布于 2025-01-12 21:40:34 字数 1418 浏览 2 评论 0原文

这是我的加密流程:

  1. 我正在我的 iOS 设备上创建密钥对。
  2. 我通过 Fetch 将公钥发送到服务器(PHP)
  3. 我在服务器上创建推送通知并使用 sodium_crypto_box_seal() 对其进行加密并成功发送
  4. 我在 iOS 设备上收到通知并尝试未能成功解密消息 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 );

然后回到react-native,我收到了推送通知

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!" 
}
})

来自node_modules/react-native-sodium/iOS/RCTSodium.m的crypto_box_seal_open()


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

知道解密失败的原因吗?任何帮助将不胜感激。我已经奋斗了好几天了

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文