anngo

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 5 Imported by: 0

README

Ann*Go

Overview

Ann*Go is an encryption and decryption utility.
Go has the crypto modules and this is an easy-to-use version of those modules.

Install

# go get github.com/elfincafe/anngo

Mode

No Mode Function
1 CBC NewAesCbc(key, iv []byte)
2 CFB NewAesCfb(key, iv []byte)
3 OFB NewAesOfb(key, iv []byte)
4 CTR NewAesCtr(key, iv []byte)

Padding

No Padding Function Note
1 PKCS7 NewPkcs7() This is a default padding.
2 ANSI X9.23 NewAnsiX923() ANSI X9.23 padding.
3 ISO 10126 NewIso10126() ISO 10126 padding.
4 Zero NewZero() Padding with 0x00. Not Recommended. There is no guarantee that it will return to normal.

Usage

import (
    "elfincafe/anngo"
    "fmt"
    "os"
)

func main() {
    iv := anngo.Generate(16) // Initial Vector
    key := anngo.Resize([]byte("Ann*Go/Example/Key"), 16)
    aes, err := NewAesCbc(key, iv)
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error: %s", err)
        os.Exit(1)
    }
    aes.Padding(NewAnsiX923())

    // Encrypt
    cipherText, err := aes.Encrypt([]byte("plain_text"))
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error: %s", err)
        os.Exit(1)
    }
    fmt.Println(cipherText)

    // Decrypt
    plainText, err := aes.Decrypt(cipherText)
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error: %s", err)
        os.Exit(1)
    }
    fmt.Println(plainText)
}

License

Ann*Go is distributed under The MIT License.
https://opensource.org/license/mit

Documentation

Overview

ANSI X9.23

ISO 10126

PKCS#7

Zero padding

Index

Constants

View Source
const (
	BlockSize int = aes.BlockSize
	AES128        = 16
	AES192        = 24
	AES256        = 32
)

Variables

This section is empty.

Functions

func GenerateIV

func GenerateIV(size int) ([]byte, error)

Types

type CBC

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

func NewCBC

func NewCBC(key []byte) *CBC

func (*CBC) AnsiX923

func (m *CBC) AnsiX923()

func (*CBC) Decrypt

func (m *CBC) Decrypt(src []byte) ([]byte, error)

func (*CBC) Encrypt

func (m *CBC) Encrypt(src []byte) ([]byte, error)

func (*CBC) IV

func (m *CBC) IV() []byte

func (*CBC) Iso10126

func (m *CBC) Iso10126()

func (*CBC) Pkcs7

func (m *CBC) Pkcs7()

func (*CBC) SetIV

func (m *CBC) SetIV(iv []byte) error

func (*CBC) ZeroPadding

func (m *CBC) ZeroPadding()

type CFB

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

func NewCFB

func NewCFB(key []byte) *CFB

func (*CFB) Decrypt

func (m *CFB) Decrypt(src []byte) ([]byte, error)

func (*CFB) Encrypt

func (m *CFB) Encrypt(src []byte) ([]byte, error)

func (*CFB) IV

func (m *CFB) IV() []byte

func (*CFB) SetIV

func (m *CFB) SetIV(iv []byte) error

type CTR

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

func NewCTR

func NewCTR(key []byte) *CTR

func (*CTR) Decrypt

func (m *CTR) Decrypt(src []byte) ([]byte, error)

func (*CTR) Encrypt

func (m *CTR) Encrypt(src []byte) ([]byte, error)

func (*CTR) IV

func (m *CTR) IV() []byte

func (*CTR) SetIV

func (m *CTR) SetIV(iv []byte) error

type ECB

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

func NewECB

func NewECB(key []byte) *ECB

func (*ECB) AnsiX923

func (m *ECB) AnsiX923()

func (*ECB) Decrypt

func (m *ECB) Decrypt(src []byte) ([]byte, error)

func (*ECB) Encrypt

func (m *ECB) Encrypt(s []byte) ([]byte, error)

func (*ECB) Iso10126

func (m *ECB) Iso10126()

func (*ECB) Pkcs7

func (m *ECB) Pkcs7()

func (*ECB) ZeroPadding

func (m *ECB) ZeroPadding()

type ModeInterface

type ModeInterface interface {
	Encrypt([]byte) ([]byte, error)
	Decrypt([]byte) ([]byte, error)
}

type OFB

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

func NewOFB

func NewOFB(key []byte) *OFB

func (*OFB) Decrypt

func (m *OFB) Decrypt(src []byte) ([]byte, error)

func (*OFB) Encrypt

func (m *OFB) Encrypt(src []byte) ([]byte, error)

func (*OFB) IV

func (m *OFB) IV() []byte

func (*OFB) SetIV

func (m *OFB) SetIV(iv []byte) error

Jump to

Keyboard shortcuts

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