Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError: Bad private key #4

Open
ikndevs opened this issue Jan 28, 2014 · 5 comments · May be fixed by #8
Open

AssertionError: Bad private key #4

ikndevs opened this issue Jan 28, 2014 · 5 comments · May be fixed by #8

Comments

@ikndevs
Copy link

ikndevs commented Jan 28, 2014

I'm trying to get jeeq to work for the first time.

I've generated a throw away address with bitcoind:

$ bitcoind getnewaddress
1k2LVG8jXmRU1Hxjto8UFuKbfYPCJT9oE
$ bitcoind dumpprivkey 1k2LVG8jXmRU1Hxjto8UFuKbfYPCJT9oE
L3BsiJ5LzwrKF7ZLGZBjhaSqMzAMFi4fBBC7RnxRW7xj9kmakGiR
$ bitcoind validateaddress 1k2LVG8jXmRU1Hxjto8UFuKbfYPCJT9oE
{
    "isvalid" : true,
    "address" : "1k2LVG8jXmRU1Hxjto8UFuKbfYPCJT9oE",
    "ismine" : true,
    "isscript" : false,
    "pubkey" : "038bd796cc06e1c11c8adc5aba0df5a9344b935c5b9165405d63461e79078c7aef",
    "iscompressed" : true,
    "account" : ""
}

Encryption seems to work OK:

$ ./jeeq.py -e -i ./test.txt -o ./test.enc -k 038bd796cc06e1c11c8adc5aba0df5a9344b935c5b9165405d63461e79078c7aef

Encrypted message to 1k2LVG8jXmRU1Hxjto8UFuKbfYPCJT9oE:
amoAAAICzAN+M/+48D5sDc+xyEp+LW/Mhy+dv2xbfCY6ZFAyUcIyHgN1geIlcapxIQhzp+5Uug8Xl8X9Re7uz+7qtg90E8b6WA==

But decryption fails:

$ ./jeeq.py -d -i ./test.enc -o ./test.dec -k L3BsiJ5LzwrKF7ZLGZBjhaSqMzAMFi4fBBC7RnxRW7xj9kmakGiR
Traceback (most recent call last):
  File "./jeeq.py", line 466, in <module>
    assert len(private_key)==32, 'Bad private key'
AssertionError: Bad private key

I vaguely feel that I should be using a 'raw' private key in some form, rather than the base58 encoded version.

Is this this case?

If so, how would I get a raw private key from bitcoind?

@jackjack-jj
Copy link
Owner

Indeed, you need to use the hexadecimal private key
For example, for the private key L3BsiJ5LzwrKF7ZLGZBjhaSqMzAMFi4fBBC7RnxRW7xj9kmakGiR, the hex private key is B2147BE63B72873F518C00FEC4C10F1A3E8F7A0153CC92C85948F0BF52942CDC (taken from https://www.bitaddress.org)
Please confirm it works
I'll change the error message, thanks for the input

@ikndevs
Copy link
Author

ikndevs commented Jan 28, 2014

Thanks, that fixed it.

$ ./jeeq.py -d -i ./test.enc -o ./test.dec -k B2147BE63B72873F518C00FEC4C10F1A3E8F7A0153CC92C85948F0BF52942CDC
Public header (size:2): 0x02cc
  Version: 0
  Checksum of pubkey: 02cc
Private header (size:6): 0x0000000f9175
  Message size: 15
  Checksum: 9175
Decrypted message: this is a test

  Hash: 9175
  Corresponds: True

Decrypted message to 1k2LVG8jXmRU1Hxjto8UFuKbfYPCJT9oE:
this is a test

@ikndevs
Copy link
Author

ikndevs commented Jan 28, 2014

Is there anyway to get the hex representation of private keys without pasting them into an untrusted web page, that could be logging/stealing my private keys?

@jackjack-jj
Copy link
Owner

I can't test from here but try DecodeBase58Check (already inside the file, line 222)
I think you'll get a trailing \x01 (that means the key is compressed), just remove it

@ikndevs
Copy link
Author

ikndevs commented Jan 29, 2014

The indentation looks a little suspect on

assert len(private_key)==32, 'Bad private key, you must give it in hexadecimal, or base58check'

I may have messed it up with my editor, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants