golang[40]-区块链-wif倒推出私钥

golang[40]-区块链-wif倒推出私钥

 2018-12-09  go  go  26  评论 字数统计: 615(字) 阅读时长: 3(分)

wif倒推出私钥

package main

import (
	"encoding/hex"
	"crypto/sha256"
	"math/big"
	"bytes"
	"fmt"
)


//base58编码
var b58Alphabet = []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")

func Base58Encode(input []byte) []byte{
	var result []byte

	x:= big.NewInt(0).SetBytes(input)

	base := big.NewInt(int64(len(b58Alphabet)))
	zero := big.NewInt(0)

	mod := &big.Int{}
	for x.Cmp(zero) != 0 {
		x.DivMod(x,base,mod)  // 对x取余数
		result =  append(result, b58Alphabet[mod.Int64()])
	}



	ReverseBytes(result)

	for _,b:=range input{

		if b ==0x00{
			result =  append([]byte{b58Alphabet[0]},result...)
		}else{
			break
		}
	}


	return result

}


//字节数组的反转
func ReverseBytes(data []byte){
	for i,j :=0,len(data) - 1;i

参考资料

https://en.bitcoin.it/wiki/Private_key
https://en.bitcoin.it/wiki/Wallet_import_format
http://gobittest.appspot.com/PrivateKey

  • 本文链接: https://dreamerjonson.com/2018/12/09/golang-40-blockchain-verifyprivatekeywif/
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY 4.0 CN协议 许可协议。转载请注明出处!

 

郑建勋(jonson)区块链工程师 & Web工程师

灾难总是接踵而至,这正是世间的常理。你以为只要哭诉一下,就会有谁来救你?如果失败了,就只能说明我不过是如此程度的男人

你可能感兴趣的:(golang)