golang[35]-区块链-私钥公钥生成

栏目: Go · 发布时间: 7年前

//生成私钥和公钥
func newKeyPair() (ecdsa.PrivateKey,[]byte){

	//生成椭圆曲线,  secp256r1 曲线。    比特币当中的曲线是secp256k1
	curve :=elliptic.P256()

	private,err :=ecdsa.GenerateKey(curve,rand.Reader)

	if err !=nil{

		fmt.Println("error")
	}
	pubkey :=append(private.PublicKey.X.Bytes(),private.PublicKey.Y.Bytes()...)
	return *private,pubkey

}


func main(){

//调用函数生成公钥
privatekey,public :=newKeyPair()

//打印私钥  曲线上的x点
	fmt.Printf("%x\n",privatekey.D.Bytes())

//打印公钥, 曲线上的x点和y点
fmt.Printf("%x",public)



}

golang[35]-区块链-私钥公钥生成


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Real-Time Rendering, Third Edition

Real-Time Rendering, Third Edition

Tomas Akenine-Moller、Eric Haines、Naty Hoffman / A K Peters/CRC Press / 2008-7-25 / USD 102.95

Thoroughly revised, this third edition focuses on modern techniques used to generate synthetic three-dimensional images in a fraction of a second. With the advent or programmable shaders, a wide varie......一起来看看 《Real-Time Rendering, Third Edition》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试