cipher

package
v3.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptFromBase64

func DecryptFromBase64(c Cipher, encrypted string) ([]byte, error)

DecryptFromBase64 decrypt base64 string data with given Cipher and returns massage

messsage, err = DecryptFromBase64(myAES, cipherString)
messsage, err = DecryptFromBase64(myBox, cipherString)
messsage, err = DecryptFromBase64(mySalsa20, cipherString)

func EncryptToBase64

func EncryptToBase64(c Cipher, msg []byte) (string, error)

EncryptToBase64 encrypt data with given Cipher and returns base64 string

cipherString, err = EncryptToBase64(myAES, []byte("Hello! 中国"))
cipherString, err = EncryptToBase64(myBox, []byte("Hello! 中国"))
cipherString, err = EncryptToBase64(mySalsa20, []byte("Hello! 中国"))

func GenerateKey

func GenerateKey() (publicKey, privateKey string)

GenerateKey generates a public/private key pair for Box. the keys is encoded by base64.RawURLEncoding

Types

type AES

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

AES use to encrypts/decrypts message with AES-256 with CTR Mode, it implemented Cipher insterface.

func NewAES

func NewAES(salt, key []byte) (*AES, error)

NewAES returns AES instance

myAES := NewAES([]byte("my salt"), []byte("my key"))

func (*AES) Decrypt

func (a *AES) Decrypt(encrypted []byte) ([]byte, error)

Decrypt decrypt data using AES.

message, err := myAES.Decrypt(cipherData)

func (*AES) Encrypt

func (a *AES) Encrypt(data []byte) ([]byte, error)

Encrypt encrypt data using AES.

cipherData, err := myAES.Encrypt([]byte("hello"))

type Box

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

Box use to encrypts/decrypts message with nacl/box (curve25519&salsa20), it implemented Cipher insterface.

func NewBox

func NewBox(peersPublicKey, privateKey string) (*Box, error)

NewBox returns Box instance

func (*Box) Decrypt

func (b *Box) Decrypt(encrypted []byte) ([]byte, error)

Decrypt decrypt data using Box

message, err := myBox.Decrypt(cipherData)

func (*Box) Encrypt

func (b *Box) Encrypt(data []byte) ([]byte, error)

Encrypt encrypt data using Box

cipherData, err := myBox.Encrypt([]byte("hello"))

type Cipher

type Cipher interface {
	// Encrypt encrypts the first block in src into dst.
	// Dst and src must overlap entirely or not at all.
	Encrypt([]byte) ([]byte, error)

	// Decrypt decrypts the first block in src into dst.
	// Dst and src must overlap entirely or not at all.
	Decrypt([]byte) ([]byte, error)
}

Cipher is using for EncryptToBase64 and DecryptFromBase64

type Salsa20

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

Salsa20 use to encrypts/decrypts message with salsa20, it implemented Cipher insterface.

func NewSalsa20

func NewSalsa20(key []byte) (*Salsa20, error)

NewSalsa20 returns Salsa20 instance.

func (*Salsa20) Decrypt

func (s *Salsa20) Decrypt(encrypted []byte) ([]byte, error)

Decrypt decrypt data using Salsa20.

message, err := mySalsa20.Decrypt(cipherData)

func (*Salsa20) Encrypt

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

Encrypt encrypt data using Salsa20.

cipherData, err := mySalsa20.Encrypt([]byte("hello"))

Jump to

Keyboard shortcuts

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