1

I am looking to generate ed25519 keys in java/kotlin. The key pair should be deterministic in that if one can provide some seed information used during the generation, they can generate the same pair again.

I understand one can achieve this using a mnemonic. Please advise me how to approach this. I am looking for a reputed library that can help me achieve this in java.

4

1 回答 1

2

您应该使用libsodium,这是文档的链接

libsodiumDJBNaCl维护最积极的实现,因此如果您使用ed25519curve25519椭圆曲线加密,您应该使用libsodium.

/中有许多绑定。JavaKotlin

它非常易于使用且安全,例如,它在恒定时间内执行标量乘法。

为了回答您关于确定性的问题,libsodium 提供了一种从种子生成确定性密钥的机制。请注意,您需要确保您的种子具有足够的熵以确保安全。

您应该调用int crypto_sign_seed_keypair(unsigned char *pk, unsigned char *sk, const unsigned char *seed);从种子生成ed25519 密钥对。

是一个在 Java 中提供与该函数绑定的库:

    /**
     * Deterministically generate a public and secret key.
     * Store the seed somewhere if you want to generate these
     * keys again.
     * @param publicKey Public key will be populated here of size {@link #PUBLICKEYBYTES}.
     * @param secretKey Secret key will be populated here of size {@link #SECRETKEYBYTES}.
     * @param seed A random seed of size {@link #SEEDBYTES}.
     * @return True if generated successfully.
     */
    boolean cryptoKxSeedKeypair(byte[] publicKey, byte[] secretKey, byte[] seed);
于 2019-12-20T10:52:38.950 回答