I used php to create a cipher text using libsodium, like that:
$contents = 'Hello World!';
$key = sodium_hex2bin('9fcc21c22142e0cb30e80da941cf1fd2221a3d273b232dac12d0d195d50c0202', '');
$nonce = sodium_hex2bin('dd024212d41933c01417bd2aa2b64682224072c8aa1573f3', '');
$cipher = sodium_crypto_secretbox($contents, $nonce, $key);
echo bin2hex($cipher);
// output: 0af8d46269eae0788ce4c20569067724402e410b35d9a0c5197be955
Then, in my react native app I used react-native-libsodium (a wrapper for java libsodium-jni) to generate the same cipher:
const test = async() => {
let cipher = await Sodium.crypto_secretbox_easy(
"Hello World!",
"dd024212d41933c01417bd2aa2b64682224072c8aa1573f3",
"9fcc21c22142e0cb30e80da941cf1fd2221a3d273b232dac12d0d195d50c0202"
);
console.log(cipher);
};
await test();
// output: 6d6ca73e3daa63a661a813c8ab6fb49f798e68965c3267eb7e1c6cdc
I tested the operation with two other javascript libraries, sodium-native and sodium-plus. In the both these situations, the result cipher text is same as php version.
For some reasons, I perfer using react-native-libsodium, but after a day I could not find why this library generates the different cipher text and how can I fix that. How can I generate the same cipher text?