aes256: github.com/mkmueller/aes256 Index | Examples | Files

package aes256

import "github.com/mkmueller/aes256"

The aes256 package provides simplified encryption and decryption functions using the standard crypto/aes package. It implements a 256 bit key length and the GCM cipher. The key may be a string of at least one character with an optional hash iteration value. The encrypted output may be a byte slice or a base-64 encoded string.

Index

Examples

Package Files

aes256.go

func Decrypt Uses

func Decrypt(key string, ciphertext []byte) ([]byte, error)

Decrypt accepts a key string and a ciphertext byte array. It returns a decrypted byte array.

Code:

ptxt, err := aes256.Decrypt("carfard", ctxt)
if err != nil {
    panic(err.Error())
}
fmt.Print(string(ptxt))

Output:

There are three great virtues of a programmer; Laziness, Impatience and Hubris

func DecryptB64 Uses

func DecryptB64(key string, ciphertext string) ([]byte, error)

DecryptB64 accepts a key string and a base-64 encoded ciphertext string. It returns a decrypted byte array.

Code:


ptxt, err = aes256.DecryptB64("carfard", base64_str)
if err != nil {
    panic(err.Error())
}

func Encrypt Uses

func Encrypt(key string, plaintext []byte) ([]byte, error)

Encrypt accepts a key string and a plaintext byte array. It returns an encrypted byte array.

Code:


ctxt, err = aes256.Encrypt("carfard", txt)
if err != nil {
    panic(err.Error())
}

func EncryptB64 Uses

func EncryptB64(key string, plaintext []byte) (string, error)

Encrypt accepts a key string and a plaintext byte array. It returns an encrypted base-64 encoded string.

Code:


base64_str, err = aes256.EncryptB64("carfard", txt)
if err != nil {
    panic(err.Error())
}

type Cipher Uses

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

func New Uses

func New(key string, rehash ...int) (*Cipher, error)

New accepts a key string and an optional rehash value. The supplied key will be rehashed the number of times indicated by the optional rehash value. A new Cipher instance will be returned.

Code:


aes, err = aes256.New("carfard")
if err != nil {
    panic(err.Error())
}

func (*Cipher) Decrypt Uses

func (ci *Cipher) Decrypt(ciphertext []byte) ([]byte, error)

Decrypt accepts a ciphertext byte array and returns a plaintext byte array.

Code:


aes, err := aes256.New("carfard")
if err != nil {
    panic(err.Error())
}
ptxt, err = aes.Decrypt(ctxt)

func (*Cipher) DecryptB64 Uses

func (ci *Cipher) DecryptB64(b64str string) ([]byte, error)

DecryptB64 accepts a base-64 encoded ciphertext string and returns a decrypted byte array.

Code:


aes, err := aes256.New("carfard")
if err != nil {
    panic(err.Error())
}
ptxt, err = aes.DecryptB64(base64_str)

func (*Cipher) Encrypt Uses

func (ci *Cipher) Encrypt(plaintext []byte) ([]byte, error)

Encrypt accepts a plaintext byte array and returns an encrypted byte array.

Code:


txt = []byte("There are three great virtues of a programmer; Laziness, Impatience and Hubris")
aes, err = aes256.New("carfard")
if err != nil {
    panic(err.Error())
}
ctxt, err = aes.Encrypt(txt)

func (*Cipher) EncryptB64 Uses

func (ci *Cipher) EncryptB64(plaintext []byte) (string, error)

EncryptB64 accepts a plaintext byte array and returns an encrypted base-64 encoded ciphertext string.

Code:


aes, err = aes256.New("carfard")
if err != nil {
    panic(err.Error())
}
base64_str, err = aes.EncryptB64(txt)

Package aes256 imports 7 packages (graph). Updated 2017-11-12. Refresh now. Tools for package owners.