0

So this is a pretty huge problem I've run into once before:

I'm using web3j-android and I'm going through the process of generating random private keys and public keys using the ECKeyPair class

Now I know private keys are generally supposed to be random 64 length strings but every once in a while (it's happened twice in around ~200 tests) I'll get this:

enter image description here

Note the sillyness here for 2 reasons:

1 - The key is triple verified as you can see in the logs, to be 63 characters

2 - a a 40 char length public address is still produced, which is weird because if it my private key was 63 characters how can that happen?

I consider this a serious error because if that were to happen silently and I were to trust it as good, there would be no way for me to sign transactions at all, much less import the wallet, the private key would be invalid. And the ether I would send to the public address would be lost forever.

The sinister part is that this all seems to check out as valid, at first glance. The key is only off by 1 char. I only happened to notice it as I was playing with the character counter on android studio's IDE.

I could run a check to make sure that the string produced is 64 char, but my overarching question is why does this happen to begin with?

1

If you picked a random number between 0 and 9,999, it would usually be 4 digits long, but you wouldn't be too surprised if every once in a while you got a result like 312 (only three digits).

Similarly, you shouldn't be surprised if you pick a number between 1 and 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 (the range of valid private keys) and it's occasionally less than 64 digits long.

A 63-digit private key is perfectly valid, so if you're having trouble signing transactions with it, that might indicate a bug in the code doing the signing. Perhaps you'll need to add the leading zero (e.g. turn "312" into "0312") to work around such a bug.

  • Ok, thanks for clearing that up. When I tried to import the address into metamask it wouldn't let me. I'll try that. – Stephen Apr 10 '18 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.