At the moment I'm playing around with ECDSA. I know that I can retrieve the private key if the same K is used to sign two messages.
I tried to use this script: Ruby Script to crack the private key. But I'm always getting an error:
signature_der_string.rb:14:in `decode': null is wrong length (OpenSSL::ASN1::ASN1Error)
My signatures start with a leading 0. If I leave out the 0 I get a different error
`decode': too long (OpenSSL::ASN1::ASN1Error)
Can you help me what I'm doing wrong?
msghash1_hex = '4992c90022d12b85555493d3dcca55671b4047c1'
msghash2_hex = 'fced62bb70b5af004e8720342d036da02009e5e8'
sig1_hex = '436c79af2252b161af0b74e3eeb4064af334c483e8708fe709c46b1aa480fa49b017fb020fbc9717c6bf50ada23a820'
sig2_hex = '436c79af2252b161af0b74e3eeb4064af334c483e8708fe734065fe380b95c601f118c047976b3007831690806e10f4'
ecdsadoes not by default encode a signature in ASN.1 notation when usingsign. It simply converts $r$ and $s$ to strings and and concatenates them. Source is inutil.py. – puzzlepalace Jun 02 '16 at 19:39sign(b'Signature', sigencode=ecdsa.util.sigencode_der)as stated in theREADME. – puzzlepalace Jun 02 '16 at 19:43string_to_numberand thensigencode_derfromecdsa'sutils.pyto do this. – puzzlepalace Jun 02 '16 at 20:42