libsodium-jni icon indicating copy to clipboard operation
libsodium-jni copied to clipboard

Can't create KeyPair from byte[] secretKey

Open niekvse opened this issue 8 years ago • 1 comments

After migrating our code from kalium to libsodium-jni, it's no longer possible to generate a KeyPair from a byte[] secretKey.

See also this change:

  • https://github.com/joshjdevl/libsodium-jni/commit/4973f074fa8faac0f0e404872e7b4d7e9a59c442#diff-3ec8890d1adb2b2729c807aac5ecd5f8

This constructor was commented out:

//    public KeyPair(byte[] secretKey) {
//        this.secretKey = secretKey;
//        checkLength(this.secretKey, SECRETKEY_BYTES);
//    }

How are we supposed to generate a KeyPair when we only have the secretKey stored locally? In the past, we used that constructor (KeyPair(byte[] secretKey)) which is now gone. We can of course subclass this class and put it back (copying all the other code as well) but it's not really ideal.

Also, your other constructor's first argument now has a confusing/wrong name:

public KeyPair(String secretKey, Encoder encoder) {
    this(encoder.decode(secretKey));
}

That String secretKey argument is now actually a seed, because it calls the KeyPair(byte[] seed) constructor.

How did you envision this upgrade path scenario from old clients using the KeyPair(byte[] secretKey) constructor? (clients that have already stored that key)

Perhaps you can add that constructor back, or add it as a static factory method (or find some other workaround for the fact they have the same signature).

niekvse avatar Nov 10 '17 13:11 niekvse

I would be happy to take a pull request for the proposal.

joshjdevl avatar Nov 10 '17 14:11 joshjdevl