crypto

package
v0.0.0-...-5d360bc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2017 License: MIT Imports: 9 Imported by: 3

README

椭圆加密算法 crypto/key.go

贴上一篇介绍: 椭圆加密算法


在blockchain中,该算法主要用于公钥和私钥。当各个节点接受到数据的时候,需要拿出该transaction的owner的公钥,对交易内容进行验证,验证成功则说明的的确确是该owner发起的交易。

所以目前程序里面的逻辑是:

  1. 用户初始化的时候,分配给该用户一个公钥和私钥。bitcoin里面一个私钥对应着多个公钥,并且是base58编码,golang原生并不是(或者我没看到,谁给解答下),所以暂时就一个公钥一个私钥。后期会考虑用上 secp256k1 方案。

  2. 用户签名的时候,用私钥签名,验证的时候,用的是公钥验证。因为不同的用户是不会拥有对方的私钥的。

  3. 公钥和私钥都是采用base58编码,base58编码

Documentation

Index

Constants

View Source
const (
	BitcoinBase58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
	Base               = 58
)
View Source
const (
	SignRLen     = 28
	SignSLen     = 28
	PublicKeyLen = 230
)

Variables

View Source
var (
	ErrInvalidLengthBytes = errors.New("invalid length bytes")
	ErrInvalidChar        = errors.New("invalid char")
)

Functions

func Sign

func Sign(payload []byte, privateKey string) (string, error)

Sign 通过私钥对数据进行签名

func Verify

func Verify(payload []byte, signature string, publicKey string) bool

Verify 验证签名对否

Types

type Base58

type Base58 struct {
	// contains filtered or unexported fields
}

func NewBase58

func NewBase58(charsStr string) (*Base58, error)

func NewBitcoinBase58

func NewBitcoinBase58() *Base58

func (*Base58) DecodeString

func (b58 *Base58) DecodeString(s string) ([]byte, error)

func (*Base58) EncodeToString

func (b58 *Base58) EncodeToString(b []byte) (string, error)

type Key

type Key struct {
	PrivateKey string
	PublicKey  string
}

func GenerateKey

func GenerateKey() *Key

GenerateKey 生成对应的公钥和私钥

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL