terl / lazysodium-java

A Java implementation of the Libsodium crypto library. For the lazy dev.
https://github.com/terl/lazysodium-java/wiki
Mozilla Public License 2.0
135 stars 48 forks source link

cryptoBoxEasyAfterNm pointer problem #59

Closed Ogromny closed 4 years ago

Ogromny commented 4 years ago

Hi,

When i run:

    fun encrypt(secretKey: Key, nonce: ByteArray, message: ByteArray): ByteArray {
        var cipherText = ByteArray(message.size)

        sodium.cryptoBoxEasyAfterNm(cipherText, message, message.size.toLong(), nonce, secretKey.asBytes)

        return cipherText
    }

I get:

munmap_chunk(): invalid pointer

Is it me or it's a bug ? What can I do ?

Sorry for my basic English

gurpreet- commented 4 years ago

Hi @Ogromny,

Thank you for reporting this. Could you please answer a few questions while I investigate further:

  1. What Java version are you using?
  2. What Lazysodium version are you using?
  3. What platform are you running this on?
gurpreet- commented 4 years ago

Oh I think I might have spotted something. The cipher length should be messageBytesLength + Box.MACBYTES. For example:

byte[] cipher = new byte[messageBytes.length + Box.MACBYTES];