# Web3开发学习笔记-签名与验签 **Published by:** [dataverse](https://paragraph.com/@lone/) **Published on:** 2021-12-29 **URL:** https://paragraph.com/@lone/web3 ## Content 消息签名:from web3.auto import w3 from eth_account.messages import encode_defunct msg = '3753e107d66160e71eac' privatekey = '1234567890abcdef' message_hash = encode_defunct(text=msg) signer = w3.eth.account.sign_message(message_hash, private_key=privatekey ) signature = signer.signature.hex() 签名验证:message_hash='0xeb276f6b7c31750f5cec63a36ca4cc1aed469bb8989a56b3e08a8152e1fa57dc' signature="0x7433929d09a0ac21b31e9b21bea923af87d6bf25d74121a37e2ca11f0ddf937c7d689a362d6d691e54a5e7f48e8444411b912425aa479e3a2a57936cffa1ded41c" sign_address = w3.eth.account.recoverHash(message_hash, signature=signature) ## Publication Information - [dataverse](https://paragraph.com/@lone/): Publication homepage - [All Posts](https://paragraph.com/@lone/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@lone): Subscribe to updates - [Twitter](https://twitter.com/layer2046): Follow on Twitter