Skip to content

Latest commit

 

History

History
70 lines (50 loc) · 2.31 KB

README.md

File metadata and controls

70 lines (50 loc) · 2.31 KB

Bitcoin ECIES

Encrypt message with bitcoin public key, and decrypt with the corresponding private key

Electrum, Electron Cash and ElectrumSV have an implementation under Tools --> Encrypt/decrypt message

Imgur

This is a GoLang version of the feature, compatible with Electrum/Electron Cash/ElectrumSV

Node.js version please refer to monkeylord/electrum-ecies

Usage

$ go get github.com/gitzhou/bitcoin-ecies

Below is a demo, or check the unit test code for an example

package main

import (
	"encoding/hex"
	"fmt"
	"github.com/gitzhou/bitcoin-ecies"
)

func main() {
	// Public key, compressed and uncompressed are both supported
	publicKey, _ := hex.DecodeString("04866269bf6c2d71968ec46797b91b207affeea74dbba1f181ff354abbfbdfe9327c58d1c0681e328f555f5aa6ec2e7543baf2b3f89ce90720d617da710ce1ea93")
	// Private key Wallet Import Format(WIF): 5KdBypVKceVrUNbWmxDJALGJ9fo9rwNYTjppps8gQb9C8VHUXzr
	// Transfer to HEX with https://gobittest.appspot.com/PrivateKey
	privateKey, _ := hex.DecodeString("ee3231b5deea48b619814d72a6e1aa04a9f521df281afad5ada89f5393941b1c")

	message := "hello world"
	encrypted, err := bitcoin_ecies.EncryptMessage(message, publicKey)
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println(encrypted)
	plain, err := bitcoin_ecies.DecryptMessage(encrypted, privateKey)
	if err != nil {
		fmt.Println(err.Error())
	}
	if message != plain {
		fmt.Println("data mismatch after encrypt and decrypt")
	}
}

Reference

Donation

Appreciated and THANK YOU 😄

You can donate Bitcoin, Bitcoin Cash or Bitcoin SV to 13L81fdKqdif6AEFAfBymXdyB3hDvBvdp9 to buy me a cup of coffee ☕

Imgur

License

MIT