Code Monkey home page Code Monkey logo

Comments (6)

gurpreet- avatar gurpreet- commented on September 21, 2024 1

Fixed in release 2.2.0 (Maven link).

Please check and verify it works @PaulSeiziger

from lazysodium-android.

gurpreet- avatar gurpreet- commented on September 21, 2024

Hello.

Thanks for the issue report. I think I came across this particular issue myself. What are you providing as the 2nd parameter (signatureLength) to crypto_sign_detached?

As mentioned in the docs, it should be null.

The actual length of the signature is put into siglen if siglen is not NULL

So something like the following should suffice...

Native way:

// Initialise somewhere at the start of program execution
SodiumAndroid sodiumAndroid = new SodiumAndroid();
LazySodiumAndroid lazySodium = new LazySodiumAndroid(sodiumAndroid);

// ....

// Get signing keypair
String message = "sign this please";
KeyPair keyPair = lazySodium.cryptoSignKeypair();
SodiumAndroid sodium = lazySodium.getSodium();

// Initialise byte arrays
byte[] messageBytes = lazySodium.bytes(message);
byte[] skBytes = keyPair.getSecretKey();
byte[] signatureBytes = new byte[Sign.BYTES];

// IMPORTANT: Put null as the second parameter
sodium.crypto_sign_detached(signatureBytes, null, messageBytes, messageBytes.length, skBytes);

// If you really want the length...
// int sigByteLength = signatureBytes.length

String signature = LazySodium.toHex(signatureBytes);
boolean result = lazySodium.cryptoSignVerifyDetached(signature, message, keyPair.getPublicKeyString()); // Returns true

Alternatively, just be lazy 😄

// Initialise somewhere at the start of program execution
SodiumAndroid sodiumAndroid = new SodiumAndroid();
LazySodiumAndroid lazySodium = new LazySodiumAndroid(sodiumAndroid);

// ....

// Get signing keypair
String message = "sign this please";
KeyPair keyPair = lazySodium.cryptoSignKeypair();
String signature = lazySodium.cryptoSignDetached(message, keyPair.getSecretKeyString());
boolean result = lazySodium.cryptoSignVerifyDetached(signature, message, keyPair.getPublicKeyString()); // Returns true

from lazysodium-android.

PaulSeiziger avatar PaulSeiziger commented on September 21, 2024

I tried to pass null, and I also tried to be lazy;) But I have this error both on the Android 8 emulator and on the real Android 4.4 device.

from lazysodium-android.

gurpreet- avatar gurpreet- commented on September 21, 2024

I think it might be related to incorrect detection of architecture. Could you provide me with:

  • the device's make and model?
  • the architecture of the device and the emulator? (x86, x86_64, etc)?

Thank you 👍

from lazysodium-android.

gurpreet- avatar gurpreet- commented on September 21, 2024

Ah never mind about sending me those details.

I've found the problem: unsigned long long * means a pointer to a long. In JNA terms this means that the function signature needs to read Pointer and not Long. E.g:

public native int crypto_sign_detached(
            byte[] signature,
            Pointer sigLength,    <--- A Pointer instead of a Long
            byte[] message,
            long messageLen,
            byte[] secretKey
    );

Note to self: I need tests for Android to prevent this from happening again!

from lazysodium-android.

PaulSeiziger avatar PaulSeiziger commented on September 21, 2024

Thanks a lot, it works on all my devices

from lazysodium-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.