Skip to content

Instantly share code, notes, and snippets.

@fivepiece
Created January 19, 2017 18:01
Show Gist options
  • Save fivepiece/3f77270cd329f75fa28b5f0101b4f531 to your computer and use it in GitHub Desktop.
Save fivepiece/3f77270cd329f75fa28b5f0101b4f531 to your computer and use it in GitHub Desktop.
rm -f /tmp/p*key.pem* /tmp/msg*; \
echo "generating and encrypting private key..."; \
openssl ecparam -name secp256k1 -genkey | \
openssl ec -conv_form compressed -out /tmp/privkey.pem -param_enc named_curve; \
openssl ec -in /tmp/privkey.pem -pubout -out /tmp/pubkey.pem; \
echo "deriving public key..."; \
openssl ec -pubin -in /tmp/pubkey.pem -noout -text; \
echo "creating and hashing message..."; \
echo -en "\x18Bitcoin Signed Message:\x0a\x06hello!" | tee /tmp/msg | \
sha256sum | xxd -r -p > /tmp/msg.sha256; \
echo "signing hash256(message) with private key..."; \
openssl dgst -sha256 -sign /tmp/privkey.pem -out /tmp/msg.sig /tmp/msg.sha256; \
xxd -c 74 -ps /tmp/msg.sig > /tmp/msg.sig.hex; \
rm /tmp/msg.sig /tmp/msg.sha256; \
echo "--verifier is given msg, msg.sig.hex, and pubkey.pem--"; \
echo "hashing message..."; \
sha256sum /tmp/msg | xxd -r -p > /tmp/msg.sha256; \
echo "verifying the signature over the message using the message hash and public key..."; \
xxd -r -p /tmp/msg.sig.hex > /tmp/msg.sig; \
openssl dgst -sha256 -verify /tmp/pubkey.pem -signature /tmp/msg.sig /tmp/msg.sha256;
cat /tmp/msg.sig.hex /tmp/msg; echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment