0

I'm making an Android application where users can login using their Ethereum account and make transactions. So far, the user can login with his private key. I want to add the option of using the 12 mnemonic words to login as well.

I am able to generate the seed (mnemonic + passphrase) using MnemonicUtils: https://github.com/web3j/web3j/blob/master/crypto/src/main/java/org/web3j/crypto/MnemonicUtils.java. But how can I generate the private key of the account from that seed? I have already tried using the code below, but it generates a different private key everytime for the exact same mnemonic.

String mnemonic="" //I put here my own mnemonic
ECKeyPair exKey= null;
        try {

               exKey = Keys.createEcKeyPair();
                } catch (InvalidAlgorithmParameterException e) {
                e.printStackTrace();
                } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
                } catch (NoSuchProviderException e) {
                e.printStackTrace();
                }

                WalletFile wallet=null;
                try {
                wallet = Wallet.createLight(mnemonic,exKey);
                } catch (CipherException e) {
                e.printStackTrace();
                }

                Credentials credentials = null;
                try {
                credentials = Credentials.create(Wallet.decrypt(mnemonic,wallet));
                } catch (CipherException e) {
                e.printStackTrace();
                }
String privateKeyGenerated = credentials.getEcKeyPair().getPrivateKey().toString(16);
                Log.d("PK", privateKeyGenerated);

0 Answers0