Git Product home page Git Product logo

authenticate's Introduction

authenticate

-- import "vimagination.zapto.org/authenticate"

Package authenticate provides a simple interface to encrypt and authenticate a

message

Usage

var (
	ErrInvalidAES  = errors.New("invalid AES key, must be 16, 24 or 32 bytes")
	ErrInvalidData = errors.New("invalid cipher text")
	ErrExpired     = errors.New("data expired")
)

Errors

type Codec

type Codec struct {
}

Codec represents an initilised encoder/decoder

func NewCodec

func NewCodec(key []byte, maxAge time.Duration) (*Codec, error)

NewCodec takes the encryption key, which should be 16, 24 or 32 bytes long, and an optional duration to create a new Codec.

The optional Duration is used to only allow messages to only be valid while it is younger than the given time.

func (*Codec) Decode

func (c *Codec) Decode(cipherText, dst []byte) ([]byte, error)

Decode takes a ciphertext slice and a destination buffer and returns the decrypted data or an error if the ciphertext is invalid or expired.

If the destination buffer is too small, or nil, it will be allocated accordingly.

func (*Codec) Encode

func (c *Codec) Encode(data, dst []byte) []byte

Encode takes a data slice and a destination buffer and returns the encrypted data.

If the destination buffer is too small, or nil, it will be allocated accordingly.

func (*Codec) Overhead

func (c *Codec) Overhead() int

Overhead returns the maximum number of bytes that the ciphertext will be longer than the plain text

authenticate's People

Contributors

mjkwoolnough avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.