Skip to content

Commit

Permalink
make encrypt to only use the new code
Browse files Browse the repository at this point in the history
  • Loading branch information
om26er committed Feb 26, 2024
1 parent 8ce13a5 commit af76c2c
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions autobahn/src/main/java/xbr/network/crypto/SealedBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<byte[], byte[]> 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);
Expand Down

0 comments on commit af76c2c

Please sign in to comment.