Android Question Help implementing libsodium in b4a

msmerce

Member
Licensed User
I want to use libsodium in my android application to create a secure connection between client and server. The huge advantages of libsodium in comparison to all other encryption libarys are features like password hashing and more modern high-level cryptographic tools . My main focus besides password hashing is the use of Curve25519 instead of RSA to make the key-exchange. The documentations of libsodium are available here: https://doc.libsodium.org/.
The question is if somebody could help me to convert the already exisiting project (which is written in Android Studio) https://github.com/joshjdevl/libsodium-jni to b4a.

Best Regards
Julius
 

msmerce

Member
Licensed User
Update:
I managed to integrate the aar file from the Android Studio project into b4a. But how can I integrate the aar file as a library in b4a so that I don't need to use JavaObject anymore? I already tried to open the aar file and integrate it into b4a using the Simple Libary compiler, but that didn't work.
Maybe someone could give me a hint.

example code to generate a Keypair:
#AdditionalJar: libsodium-jni-release.aar

Sub testlibsodium
    Private NativeMe As JavaObject
    NativeMe.InitializeContext
    NativeMe.RunMethod("generateEncryptionKeyPair", Null)

    Dim pub() As Byte = NativeMe.RunMethod("publicKey", Null)
    Dim priv() As Byte = NativeMe.RunMethod("privateKey", Null)

    Dim b64 As Base64
    Log(b64.EncodeBtoS(pub, 0, pub.Length))
    Log(b64.EncodeBtoS(priv, 0, priv.Length))
End Sub

#If Java
import org.libsodium.jni.SodiumConstants;
import org.libsodium.jni.crypto.Random;
import org.libsodium.jni.keys.KeyPair;

KeyPair encryptionKeyPair;

public void generateEncryptionKeyPair() {
    byte[] seed = new Random().randomBytes(SodiumConstants.SECRETKEY_BYTES);
    encryptionKeyPair = new KeyPair(seed);
}

public byte[] privateKey() {
    return encryptionKeyPair.getPrivateKey().toBytes();
}

public byte[] publicKey() {
    return encryptionKeyPair.getPublicKey().toBytes();
}
#End If
 
Top