crypto

package
v0.0.0-...-06ecd44 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package crypto provides a small wrapper around cryptopasta.

Index

Constants

View Source
const AES256KeyLengthInBytes = 32

AES256KeyLengthInBytes is the length, in bytes, of a 256-bit AES key

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(ciphertext []byte, key *AES256Key) ([]byte, error)

Decrypt decrypts the ciphertext with the provided key and returns the result.

func DecryptStringFromBase64

func DecryptStringFromBase64(base64Ciphertext string, key *AES256Key) (plaintext string, err error)

DecryptStringFromBase64 decodes the provided base64 string (e.g. from a previous call to EncryptStringToBase64), decrypts the result with the provided key, and returns the resulting string.

func Encrypt

func Encrypt(plaintext []byte, key *AES256Key) ([]byte, error)

Encrypt encrypts the plaintext with the provided key and returns the result.

func EncryptStringToBase64

func EncryptStringToBase64(plaintext string, key *AES256Key) (base64Ciphertext string, err error)

EncryptStringToBase64 encrypts the plaintext with the provided key and returns the base64-encoded result.

func Equal

func Equal(k1, k2 *AES256Key) bool

Equal returns a boolean reporting whether a and b are the same length and contain the same bytes. A nil argument is equivalent to an empty slice.

Types

type AES256Key

type AES256Key [AES256KeyLengthInBytes]byte

AES256Key represents a 256-bit AES key

func NewAESKeyFromBase64

func NewAESKeyFromBase64(base64Key string) (*AES256Key, error)

NewAESKeyFromBase64 loads the base64-encoded string into the current AES256Key.

func NewRandomAESKey

func NewRandomAESKey() *AES256Key

NewRandomAESKey returns a new, cryptographically generated 256-bit AES key. NewRandomAESKey will panic if the source of randomness fails.

func (*AES256Key) ToBase64

func (key *AES256Key) ToBase64() string

ToBase64 converts the AES key to a base64-encoded string.

Jump to

Keyboard shortcuts

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