crypto

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 15 Imported by: 14

Documentation

Overview

---------------------------------------------------------------------------------------------

  • Copyright (c) IBAX. All rights reserved.
  • See LICENSE in the project root for license information. *--------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------

  • Copyright (c) IBAX. All rights reserved.
  • See LICENSE in the project root for license information. *--------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------

  • Copyright (c) IBAX. All rights reserved.
  • See LICENSE in the project root for license information. *--------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------

  • Copyright (c) IBAX. All rights reserved.
  • See LICENSE in the project root for license information. *--------------------------------------------------------------------------------------------

Index

Constants

This section is empty.

Variables

View Source
var AsymAlgo_name = map[int32]string{
	0: "ECC_P256",
	1: "ECC_Secp256k1",
	2: "SM2",
	3: "ECC_P512",
}
View Source
var AsymAlgo_value = map[string]int32{
	"ECC_P256":      0,
	"ECC_Secp256k1": 1,
	"SM2":           2,
	"ECC_P512":      3,
}
View Source
var HashAlgo_name = map[int32]string{
	0: "SHA256",
	1: "KECCAK256",
	2: "SM3",
	3: "SHA3_256",
}
View Source
var HashAlgo_value = map[string]int32{
	"SHA256":    0,
	"KECCAK256": 1,
	"SM3":       2,
	"SHA3_256":  3,
}
View Source
var SymAlgo_name = map[int32]string{
	0: "AES",
	1: "SM4",
}
View Source
var SymAlgo_value = map[string]int32{
	"AES": 0,
	"SM4": 1,
}

Functions

func Address

func Address(pubKey []byte) int64

Address gets int64 address from the public key

func CalcChecksum

func CalcChecksum(input []byte) uint64

CalcChecksum is calculates checksum, returns crc64 sum.

func CutPub

func CutPub(pubKey []byte) []byte

CutPub removes the first 04 byte

func DoubleHash

func DoubleHash(msg []byte) []byte

func GenHexKeys

func GenHexKeys() (string, string, error)

GenHexKeys generates a random pair of private and public hex keys.

func GenKeyPair

func GenKeyPair() ([]byte, []byte, error)

GenKeyPair generates a random pair of private and public binary keys.

func GetHMAC

func GetHMAC(secret string, message string) ([]byte, error)

func GetWalletIDByPublicKey

func GetWalletIDByPublicKey(publicKey []byte) (int64, error)

GetWalletIDByPublicKey converts public key to wallet id

func Hash

func Hash(msg []byte) []byte

func HashHex

func HashHex(input []byte) string

func HexToPub

func HexToPub(pub string) ([]byte, error)

HexToPub encodes hex string to []byte of pub key

func InitAsymAlgo

func InitAsymAlgo(s string)

func InitHashAlgo

func InitHashAlgo(s string)

func KeyToAddress

func KeyToAddress(pubKey []byte) string

KeyToAddress converts a public key to chain address XXXX-...-XXXX.

func PrivateToPublic

func PrivateToPublic(key []byte) ([]byte, error)

PrivateToPublic returns the public key for the specified private key.

func PubToHex

func PubToHex(pub []byte) string

PubToHex decodes []byte of pub key to hex string

func RandSeq

func RandSeq(n int) string

RandSeq is returning random string

func RepeatPrefixed

func RepeatPrefixed(input string) []byte

func Sign

func Sign(privateKey, data []byte) ([]byte, error)

func SignString

func SignString(privateKeyHex, data string) ([]byte, error)

func Verify

func Verify(public, data, signature []byte) (bool, error)

Types

type AsymAlgo

type AsymAlgo int32

AsymAlgo is asymmetric algorithms

const (
	AsymAlgo_ECC_P256      AsymAlgo = 0
	AsymAlgo_ECC_Secp256k1 AsymAlgo = 1
	AsymAlgo_SM2           AsymAlgo = 2
	AsymAlgo_ECC_P512      AsymAlgo = 3
)

func (AsymAlgo) EnumDescriptor

func (AsymAlgo) EnumDescriptor() ([]byte, []int)

func (AsymAlgo) String

func (x AsymAlgo) String() string

type AsymProvider

type AsymProvider interface {
	GenKeyPair() ([]byte, []byte, error)
	Sign(privateKey, hash []byte) ([]byte, error)
	// Verify checks if forSign has been signed with corresponding to public the private key
	Verify(public, hash, sign []byte) (bool, error)
	PrivateToPublic(key []byte) ([]byte, error)
}

func GetAsymProvider

func GetAsymProvider() AsymProvider

func NewAsymAlgo

func NewAsymAlgo(a AsymAlgo) AsymProvider

type HashAlgo

type HashAlgo int32

HashAlgo is hash algorithms

const (
	HashAlgo_SHA256    HashAlgo = 0
	HashAlgo_KECCAK256 HashAlgo = 1
	HashAlgo_SM3       HashAlgo = 2
	HashAlgo_SHA3_256  HashAlgo = 3
)

func (HashAlgo) EnumDescriptor

func (HashAlgo) EnumDescriptor() ([]byte, []int)

func (HashAlgo) String

func (x HashAlgo) String() string

type HashProvider

type HashProvider interface {
	// GetHMAC returns HMAC hash
	GetHMAC(secret string, msg string) ([]byte, error)
	// GetHash returns hash of passed bytes
	GetHash(msg []byte) []byte
	// DoubleHash returns double hash of passed bytes
	DoubleHash(msg []byte) []byte
}

func GetHashProvider

func GetHashProvider() HashProvider

func NewHashAlgo

func NewHashAlgo(a HashAlgo) HashProvider

type SymAlgo

type SymAlgo int32

SymAlgo is symmetric algorithms

const (
	SymAlgo_AES SymAlgo = 0
	SymAlgo_SM4 SymAlgo = 1
)

func (SymAlgo) EnumDescriptor

func (SymAlgo) EnumDescriptor() ([]byte, []int)

func (SymAlgo) String

func (x SymAlgo) String() string

Directories

Path Synopsis
symalgo
aes
---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------

Jump to

Keyboard shortcuts

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