Last active
December 4, 2017 17:29
-
-
Save nonsense/64dd6a0e18492c32c43d8098151f98ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestPythonCrypto(t *testing.T) { | |
signature := "638A54215D80A6713C8D523A6ADC4E6E73652D859103A36B700851CB0E61B66B8EBFC1A610C57D732EC6E0A8F06A9A7A28DF5051ECE514702FF9CDFF0B11F454" | |
key := "03ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd3138" | |
//keccak 256 digest | |
//content := "f854018664697363763582765f82696490736563703235366b312d6b656363616b83697034847f00000189736563703235366b31a103ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd3138" | |
digest := "d301ce462d3e639518f482c7f03821fec1e602018630ce621e1e7851c12343a6" | |
bsig, err := hex.DecodeString(signature) | |
if err != nil { | |
t.Fatal(err) | |
} | |
bdigest, err := hex.DecodeString(digest) | |
if err != nil { | |
t.Fatal(err) | |
} | |
bpk, err := hex.DecodeString(key) | |
if err != nil { | |
t.Fatal(err) | |
} | |
pk, err := btcec.ParsePubKey(bpk, btcec.S256()) | |
if err != nil { | |
t.Fatal(err) | |
} | |
sign, err := btcec.ParseSignature(bsig, btcec.S256()) | |
if err != nil { | |
t.Fatal(err) | |
} | |
if !sign.Verify(bdigest, (*btcec.PublicKey)(pk)) { | |
t.Fatal("signature not valid") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment