crypto

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: Apache-2.0 Imports: 10 Imported by: 1

README

GoDoc

crypto

Wrappers for hashing, signing, random values generation etc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base32Decode

func Base32Decode(str string) ([]byte, error)

func Base32DecodeNP

func Base32DecodeNP(str string) ([]byte, error)

func Base32Encode

func Base32Encode(data []byte) string

func Base32EncodeNP

func Base32EncodeNP(data []byte) string

func Base64Decode

func Base64Decode(str string) ([]byte, error)

func Base64DecodeNP

func Base64DecodeNP(str string) ([]byte, error)

Base64DecodeNP - no padding decode base 64

func Base64Encode

func Base64Encode(data []byte) string

func Base64EncodeNP

func Base64EncodeNP(data []byte) string

Base64EncodeNP - no padding encode base 64

func GenKeyPair

func GenKeyPair() (privateKey, publicKey string)

GenKeyPair generates new ed25519 private and public keys.

func HashData

func HashData(data interface{}) (string, error)

HashData serializes `data` and generate hash.

func HashDataRaw

func HashDataRaw(data interface{}) (string, error)

HashDataRaw serializes `data` and generate hash.

func HashStrings

func HashStrings(strs ...string) string

HashStrings joins passed strings and hash it.

func HashStringsRaw

func HashStringsRaw(strs ...string) string

HashStringsRaw joins passed strings and hash it.

func RandomString

func RandomString(length int, args ...string) (walletID string)

RandomString generates new random base32 Encoded random string.

func SignData

func SignData(privKey string, data interface{}) (string, error)

SignData serializes the `data` and signs it using the `privateKey`.

func SignMessage

func SignMessage(privKey, message string) (string, error)

SignMessage signs the `message` using the `privateKey`.

func VerifySignature

func VerifySignature(pubKey, message, signature string) (bool, error)

VerifySignature checks is valid `signature` of `message`.

Types

type KP

type KP struct {
	Private Key `json:"private" yaml:"private"`
	Public  Key `json:"public" yaml:"public"`
}

KP (KeyPair) is a representation of the `ed25519` key pair with common methods.

func RandomKP

func RandomKP() KP

RandomKP generates new KeyPair.

func (*KP) SetPrivKeyFromString

func (kp *KP) SetPrivKeyFromString(privateKey string) (err error)

SetPrivKeyFromString - set private key from string

func (*KP) SetPubKeyFromString

func (kp *KP) SetPubKeyFromString(publicKey string) (err error)

SetPubKeyFromString - set public key from string

func (*KP) Sign

func (kp *KP) Sign(data []byte) (string, error)

Sign signs the `data`.

func (*KP) SignData

func (kp *KP) SignData(data interface{}) (string, error)

SignData serializes the `data` and signs it using the `privateKey`.

func (*KP) VerifySignature

func (kp *KP) VerifySignature(message, signature string) (bool, error)

VerifySignature checks is valid `signature` of `message`.

type Key

type Key []byte

Key is a type for

func FromString

func FromString(keyS string) (*Key, error)

FromString initialize type from string key

func (Key) MarshalJSON

func (key Key) MarshalJSON() ([]byte, error)

MarshalJSON is a realization of the `Marshaller` interface.

func (*Key) Scan

func (key *Key) Scan(src interface{}) error

Scan is realization of the `Scanner` interface.

func (Key) String

func (key Key) String() string

String is a realization of the `Stringer` interface.

func (Key) ToBytes

func (key Key) ToBytes() []byte

ToBytes cast `key` to `[]byte `.

func (Key) ToPrivate

func (key Key) ToPrivate() ed25519.PrivateKey

ToPrivate cast `key` to `ed25519.PrivateKey`.

func (Key) ToPublicKey

func (key Key) ToPublicKey() ed25519.PublicKey

ToPublicKey cast `key` to `ed25519.PublicKey`.

func (*Key) UnmarshalJSON

func (key *Key) UnmarshalJSON(data []byte) error

UnmarshalJSON is a realization of the `Unmarshaller` interface.

func (Key) Value

func (key Key) Value() (driver.Value, error)

Value is a realization of the `Valuer` interface.

Jump to

Keyboard shortcuts

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