cipher

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2018 License: LGPL-3.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// ScryptKDF name
	ScryptKDF = "scrypt"

	// StandardScryptN N parameter of Scrypt encryption algorithm
	StandardScryptN = 1 << 12

	// StandardScryptR r parameter of Scrypt encryption algorithm
	StandardScryptR = 8

	// StandardScryptP p parameter of Scrypt encryption algorithm
	StandardScryptP = 1

	// ScryptDKLen get derived key length
	ScryptDKLen = 32
)

Variables

View Source
var (
	// ErrVersionInvalid version not supported
	ErrVersionInvalid = errors.New("version not supported")

	// ErrKDFInvalid cipher not supported
	ErrKDFInvalid = errors.New("kdf not supported")

	// ErrCipherInvalid cipher not supported
	ErrCipherInvalid = errors.New("cipher not supported")

	// ErrDecrypt decrypt failed
	ErrDecrypt = errors.New("could not decrypt key with given passphrase")
)

Functions

func RandomCSPRNG

func RandomCSPRNG(n int) []byte

RandomCSPRNG a cryptographically secure pseudo-random number generator

Types

type Cipher

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

Cipher encrypt cipher

func NewCipher

func NewCipher(alg uint8) *Cipher

NewCipher returns a new cipher

func (*Cipher) Decrypt

func (c *Cipher) Decrypt(data []byte, passphrase []byte) ([]byte, error)

Decrypt decrypts data, returning the origin data

func (*Cipher) DecryptKey

func (c *Cipher) DecryptKey(keyjson []byte, passphrase []byte) ([]byte, error)

DecryptKey decrypts a key, returning the private key itself.

func (*Cipher) Encrypt

func (c *Cipher) Encrypt(data []byte, passphrase []byte) ([]byte, error)

Encrypt scrypt encrypt

func (*Cipher) EncryptKey

func (c *Cipher) EncryptKey(address string, data []byte, passphrase []byte) ([]byte, error)

EncryptKey encrypt key with address

type Encrypt

type Encrypt interface {

	// Encrypt encrypts data with passphrase,
	Encrypt(data []byte, passphrase []byte) ([]byte, error)

	// EncryptKey encrypt key with address
	EncryptKey(address string, data []byte, passphrase []byte) ([]byte, error)

	// Decrypt decrypts data with passphrase,  returning origin data.
	Decrypt(data []byte, passphrase []byte) ([]byte, error)

	// DecryptKey decrypts a key from a json blob, returning the private key itself.
	DecryptKey(keyjson []byte, passphrase []byte) ([]byte, error)
}

Encrypt interface for encrypt

type Scrypt

type Scrypt struct {
}

Scrypt scrypt encrypt

func (*Scrypt) Decrypt

func (s *Scrypt) Decrypt(data []byte, passphrase []byte) ([]byte, error)

Decrypt decrypts data from a json blob, returning the origin data

func (*Scrypt) DecryptKey

func (s *Scrypt) DecryptKey(keyjson []byte, passphrase []byte) ([]byte, error)

DecryptKey decrypts a key from a json blob, returning the private key itself.

func (*Scrypt) Encrypt

func (s *Scrypt) Encrypt(data []byte, passphrase []byte) ([]byte, error)

Encrypt scrypt encrypt

func (*Scrypt) EncryptKey

func (s *Scrypt) EncryptKey(address string, data []byte, passphrase []byte) ([]byte, error)

EncryptKey encrypt key with address

func (*Scrypt) ScryptEncrypt

func (s *Scrypt) ScryptEncrypt(data []byte, passphrase []byte, N, r, p int) ([]byte, error)

ScryptEncrypt encrypts a key using the specified scrypt parameters into a json blob that can be decrypted later on. N is a CPU/memory cost parameter, which must be a power of two greater than 1. r and p must satisfy r * p < 2³⁰. If the parameters do not satisfy the limits, the function returns a nil byte slice and an error.

Jump to

Keyboard shortcuts

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