From af76c2c94d115f91cfa389529e8ab8d3fe6812a9 Mon Sep 17 00:00:00 2001 From: Omer Akram Date: Mon, 26 Feb 2024 14:26:47 +0500 Subject: [PATCH] make encrypt to only use the new code --- .../main/java/xbr/network/crypto/SealedBox.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/autobahn/src/main/java/xbr/network/crypto/SealedBox.java b/autobahn/src/main/java/xbr/network/crypto/SealedBox.java index 4d164d47..0fcbba4e 100644 --- a/autobahn/src/main/java/xbr/network/crypto/SealedBox.java +++ b/autobahn/src/main/java/xbr/network/crypto/SealedBox.java @@ -9,11 +9,9 @@ import org.bouncycastle.util.Arrays; import org.libsodium.jni.encoders.Encoder; -import static org.libsodium.jni.NaCl.sodium; import static org.libsodium.jni.SodiumConstants.NONCE_BYTES; import static org.libsodium.jni.SodiumConstants.PUBLICKEY_BYTES; import static org.libsodium.jni.SodiumConstants.SECRETKEY_BYTES; -import static org.libsodium.jni.crypto.Util.isValid; import io.crossbar.autobahn.utils.Pair; import xbr.network.Util; @@ -54,17 +52,9 @@ public SealedBox(String publicKey, String privateKey, Encoder encoder) { } public byte[] encrypt(byte[] message) { - byte[] ct = new byte[message.length + SEAL_BYTES]; - isValid(sodium().crypto_box_seal( - ct, message, message.length, publicKey), - "Encryption failed"); - return ct; - } - - public byte[] encrypt(byte[] message, byte[] recipientPublicKey) { Pair keyPair = Util.generateX25519KeyPair(); - byte[] nonce = createNonce(keyPair.first, recipientPublicKey); - byte[] sharedSecret = computeSharedSecret(recipientPublicKey, keyPair.second); + byte[] nonce = createNonce(keyPair.first, publicKey); + byte[] sharedSecret = computeSharedSecret(publicKey, keyPair.second); XSalsa20Engine cipher = new XSalsa20Engine(); ParametersWithIV params = new ParametersWithIV(new KeyParameter(sharedSecret), nonce);