React-native-sodium 与 PHP 的钠在 crypto_box_seal_open() 处失败
这是我的加密流程:
- 我正在我的 iOS 设备上创建密钥对。
- 我通过 Fetch 将公钥发送到服务器(PHP)
- 我在服务器上创建推送通知并使用 sodium_crypto_box_seal() 对其进行加密并成功发送
- 我在 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:
- I'm creating a key-pair on my iOS device.
- I send to public key to the server (PHP) via Fetch
- I create a push-notification on the server and encrypts it with sodium_crypto_box_seal() and sends it sucessfully
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论