elrond-sdk-erdpy icon indicating copy to clipboard operation
elrond-sdk-erdpy copied to clipboard

Trying to create a new wallet or deriving an existing one give "bad key length"

Open jamiebullock opened this issue 3 years ago • 9 comments

On macOS 12.1, M1 Macbook Air...

erdpy -v      
erdpy 1.0.24

If I do either:

erdpy wallet new --pem

Or:

erdpy --verbose wallet derive ./walletKey.pem --mnemonic

I get the following error:

Traceback (most recent call last):
  File "/Users/jamie/elrondsdk/erdpy-venv/bin/erdpy", line 8, in <module>
    sys.exit(main())
  File "/Users/jamie/elrondsdk/erdpy-venv/lib/python3.8/site-packages/erdpy/cli.py", line 32, in main
    _do_main()
  File "/Users/jamie/elrondsdk/erdpy-venv/lib/python3.8/site-packages/erdpy/cli.py", line 58, in _do_main
    args.func(args)
  File "/Users/jamie/elrondsdk/erdpy-venv/lib/python3.8/site-packages/erdpy/cli_wallet.py", line 93, in new_wallet
    secret_key, pubkey = wallet.derive_keys(mnemonic)
  File "/Users/jamie/elrondsdk/erdpy-venv/lib/python3.8/site-packages/erdpy/wallet/core.py", line 26, in derive_keys
    bip39seed = mnemonic_to_bip39seed(mnemonic)
  File "/Users/jamie/elrondsdk/erdpy-venv/lib/python3.8/site-packages/erdpy/wallet/core.py", line 39, in mnemonic_to_bip39seed
    stretched = hashlib.pbkdf2_hmac("sha512", mnemonic, passphrase, BIP39_PBKDF2_ROUNDS)
ValueError: [digital envelope routines: CRYPTO_internal] bad key length

jamiebullock avatar Feb 01 '22 12:02 jamiebullock

OK, I've done a little investigation on this, and it seems that the password argument to pbkdf2_hmac is limited to 128 bytes.

My guess is this is a limitation imposed by the underlying openssl implementation.

jamiebullock avatar Feb 01 '22 14:02 jamiebullock

Hey,

I have the same error on macOS 12.2.1, M1 Pro.

Do you have a workaround or something?

IonutSKL avatar Feb 24 '22 22:02 IonutSKL

@jamiebullock, @IonutSKL, thank you for reporting the issue :pray:

Until we come back with an investigation and a fix, do you think you can use the following CLI to create wallets (or the web wallet, for that matter):

https://github.com/ElrondNetwork/erdwalletjs-cli

Further reference:

  • https://docs.elrond.com/developers/creating-wallets

andreibancioiu avatar Feb 25 '22 07:02 andreibancioiu

and still, how to derive the pem file from mnemonic? because with the erdwalletjs is not possible

adrianslr avatar Feb 26 '22 01:02 adrianslr

and still, how to derive the pem file from mnemonic? because with the erdwalletjs is not possible

@pislaru, erdpy commands support json wallet files as well - see the parameters --keyfile, --passfile :pray:

andreibancioiu avatar Feb 28 '22 13:02 andreibancioiu

@jamiebullock Is this reproducible on M1 with erdpy 1.1.0?

ccorcoveanu avatar Mar 04 '22 11:03 ccorcoveanu

Hey @ccorcoveanu,

I've tried again after erdpy update.. so, my version is now:

erdpy --version
erdpy 1.2.1

but, same error:

ib/python/site-packages/erdpy/wallet/core.py", line 39, in mnemonic_to_bip39seed
    stretched = hashlib.pbkdf2_hmac("sha512", mnemonic, passphrase, BIP39_PBKDF2_ROUNDS)
ValueError: [digital envelope routines: CRYPTO_internal] bad key length

IonutSKL avatar Mar 07 '22 21:03 IonutSKL

hello there,

up on this ? same error...

lleoooell avatar May 06 '22 00:05 lleoooell

Same man, I was following this tutorial: https://docs.elrond.com/developers/tutorials/your-first-dapp/#create-an-owner-wallet and encounter the same error when trying to derive the pem file from mnemonic. Any fix yet guys?

vietcuongmonad avatar Sep 08 '22 04:09 vietcuongmonad

Hello,

We are now at mxpy v7.1.0 and as far as we've tested this, the issue does not persist anymore. The following command should work fine: mxpy wallet new --format=pem --outfile=test.pem

popenta avatar Jul 20 '23 10:07 popenta