crypto

package
v6.4.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2020 License: BSD-3-Clause Imports: 10 Imported by: 0

README

crypto

功能

  • 支持 ed25519, secp256k1, sm2
  • 统一的 PrivKey,Pubkey, Signature 接口, 详见 crypto.go

依赖

  • sm2 编译依赖 gmssl 2.0 版本
  • 安装:bash ./deps/install_gmssl.sh

Documentation

Overview

Package crypto 加解密、签名接口定义

Index

Constants

View Source
const (
	SignNameED25519 = "ed25519"
)

const

Variables

This section is empty.

Functions

func CRandBytes

func CRandBytes(numBytes int) []byte

CRandBytes This uses the OS and the Seed(s).

func CRandHex

func CRandHex(numDigits int) string

CRandHex RandHex(24) gives 96 bits of randomness, strong enough for most purposes.

func CReader

func CReader() io.Reader

CReader Returns a crand.Reader mixed with user-supplied entropy

func GetName

func GetName(ty int) string

GetName 获取name

func GetType

func GetType(name string) int

GetType 获取type

func MixEntropy

func MixEntropy(seedBytes []byte)

MixEntropy Mix additional bytes of randomness, e.g. from hardware, user-input, etc. It is OK to call it multiple times. It does not diminish security.

func Register

func Register(name string, driver Crypto)

Register 注册

func RegisterType

func RegisterType(name string, ty int)

RegisterType 注册类型

func Ripemd160

func Ripemd160(bytes []byte) []byte

Ripemd160 加密算法

func Sha256

func Sha256(bytes []byte) []byte

Sha256 加密算法

func Sm3Hash

func Sm3Hash(msg []byte) []byte

Sm3Hash 加密算法

Types

type CertSignature

type CertSignature struct {
	Signature []byte
	Cert      []byte
}

CertSignature 签名

type Crypto

type Crypto interface {
	GenKey() (PrivKey, error)
	SignatureFromBytes([]byte) (Signature, error)
	PrivKeyFromBytes([]byte) (PrivKey, error)
	PubKeyFromBytes([]byte) (PubKey, error)
}

Crypto 加密

func New

func New(name string) (c Crypto, err error)

New new

type PrivKey

type PrivKey interface {
	Bytes() []byte
	Sign(msg []byte) Signature
	PubKey() PubKey
	Equals(PrivKey) bool
}

PrivKey 私钥

type PubKey

type PubKey interface {
	Bytes() []byte
	KeyString() string
	VerifyBytes(msg []byte, sig Signature) bool
	Equals(PubKey) bool
}

PubKey 公钥

type Signature

type Signature interface {
	Bytes() []byte
	IsZero() bool
	String() string
	Equals(Signature) bool
}

Signature 签名

Directories

Path Synopsis
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.

Jump to

Keyboard shortcuts

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