crypto

package module
v0.0.0-...-3f33717 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

README

crypto

crypto is a cryptography library used in NKN.

Usage

import "github.com/nknorg/crypto"

Digest
  • SHA256
	SHA256.Hash(value []byte) []byte
  • SHA3_256
	SHA3_256.Hash(value []byte) []byte
  • RIPEMD160
	RIPEMD160.Hash(value []byte) []byte
Cipher
  • AES-CBC
   ToAesKey(pwd []byte) []byte
   AesEncrypt(plaintext []byte, key []byte, iv []byte)  ([]byte, error)
   AesDecrypt(ciphertext []byte, key []byte, iv []byte) ([]byte, error)
Signature
  • Generate Key
	// ECDSA(p256r1)
	P256R1.New() (*Keypair, error)
	// ED25519
	ED25519.New() (*Keypair, error)
  • Sign & Verify
	type PubKey interface {
		EqualTo(pk PubKey) bool
		Compress(isCommpressed bool) ([]byte, error)
		DeCompress(encodeData []byte) error
		Marshal() ([]byte, error)
		Unmarshal(data []byte) error
		Verify(data []byte, signature []byte) error
	}

	type PrivKey interface {
		PublicKey() PubKey
		Marshal() ([]byte, error)
		Unmarshal(data []byte) error
		Sign(data []byte) ([]byte, error)
	}

	type Keypair struct {
		pk PubKey
		sk PrivKey
	}
Random number
	RandBytes(b []byte) (n int, err error)
License

crypto is under APACHE-2.0 license. See LICENSE for details.

Documentation

Index

Constants

View Source
const (
	HASH256_LEN = 32
	HASH160_LEN = 20
)

Variables

This section is empty.

Functions

func AesDecrypt

func AesDecrypt(ciphertext []byte, key []byte, iv []byte) ([]byte, error)

func AesEncrypt

func AesEncrypt(plaintext []byte, key []byte, iv []byte) ([]byte, error)

func RandBytes

func RandBytes(b []byte) (n int, err error)

func ToAesKey

func ToAesKey(pwd []byte) []byte

Types

type HASH

type HASH uint32
const (
	SHA256    HASH = 1
	SHA3_256  HASH = 2
	RIPEMD160 HASH = 3
)

func (HASH) Hash

func (h HASH) Hash(value []byte) []byte

func (HASH) Name

func (h HASH) Name() string

func (HASH) Size

func (h HASH) Size() int

type SIGALGO

type SIGALGO uint32
const (
	P256R1  SIGALGO = 1
	ED25519 SIGALGO = 2
)

func (SIGALGO) New

func (sig SIGALGO) New() (*signature.Keypair, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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