crypto

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: GPL-3.0 Imports: 7 Imported by: 1

Documentation

Overview

Package crypto contains helper functions and interfaces that can be used to easily read and write different types of encrypted data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAes

func NewAes(k []byte) (cipher.Block, error)

NewAes attempts to create a new AES block cipher from the provided key data. Errors will be returned if the key length is invalid.

func NewBlockReader added in v0.4.4

func NewBlockReader(b cipher.Block, iv []byte, r io.Reader) (io.ReadCloser, error)

NewBlockReader creates a data.Reader type from the specified block cipher, IV and Reader.

This is used to Decrypt data. This function returns an error if the blocksize of the Block does not equal the length of the supplied IV.

This uses CFB mode.

func NewBlockWriter added in v0.4.4

func NewBlockWriter(b cipher.Block, iv []byte, w io.Writer) (io.WriteCloser, error)

NewBlockWriter creates a data.Reader type from the specified block cipher, IV and Writer.

This is used to Encrypt data. This function returns an error if the blocksize of the Block does not equal the length of the supplied IV.

This uses CFB mode.

func NewCBKReader added in v0.4.4

func NewCBKReader(c CBK, r io.Reader) io.Reader

NewCBKReader creates an io.ReadCloser type from the specified CBK cipher and Reader.

func NewCBKWriter added in v0.4.4

func NewCBKWriter(c CBK, w io.Writer) io.WriteCloser

NewCBKWriter creates an io.WriteCloser type from the specified CBK cipher and Writer.

func NewXORReader added in v0.4.4

func NewXORReader(x XOR, r io.Reader) io.Reader

NewXORReader creates an io.WriteCloser type from the specified XOR cipher and Reader.

This creates a Block cipher with a auto-generated IV based on the key value. To control the IV value, use the 'NewCBKReader' function instead.

func NewXORWriter added in v0.4.4

func NewXORWriter(x XOR, w io.Writer) io.WriteCloser

NewXORWriter creates an io.WriteCloser type from the specified XOR cipher and Writer.

This creates a Block cipher with a auto-generated IV based on the key value. To control the IV value, use the 'NewBlockWriter' function instead.

func UnwrapString added in v0.3.4

func UnwrapString(key, data []byte) string

UnwrapString is used to un-encode a string written in a XOR byte array "encrypted" by the specified key.

This function returns the string value of the result but also modifies the input array, which can be used to re-use the resulting string.

Types

type CBK

type CBK struct {
	// Random Source to use for data generation from keys.
	// This source MUST be repeatable.
	Source source

	A, B byte
	C, D byte
	// contains filtered or unexported fields
}

CBK is the representation of the CBK Cipher. CBK is a block based cipher that allows for a variable size index in encoding.

func NewCBK

func NewCBK(d int) CBK

NewCBK returns a new CBK Cipher with the D value specified. The other A, B and C values are randomly generated at runtime.

func NewCBKEx

func NewCBKEx(d int, sz int, src source) (CBK, error)

NewCBKEx returns a new CBK Cipher with the D value, BlockSize and Entropy source specified. The other A, B and C values are randomly generated at runtime.

func NewCBKSource added in v0.1.0

func NewCBKSource(a, b, c, d, sz byte) (CBK, error)

NewCBKSource returns a new CBK Cipher with the A, B, C, D, BlockSize values specified.

func (*CBK) BlockSize

func (e *CBK) BlockSize() int

BlockSize returns the cipher's block BlockSize.

func (*CBK) Decrypt

func (e *CBK) Decrypt(dst, src []byte)

Decrypt decrypts the first block in src into dst. Dst and src must overlap entirely or not at all.

func (*CBK) Deshuffle

func (e *CBK) Deshuffle(b []byte)

Deshuffle will reverse the switch around the bytes in the array based on the Cipher bytes.

func (*CBK) Encrypt

func (e *CBK) Encrypt(dst, src []byte)

Encrypt encrypts the first block in src into dst. Dst and src must overlap entirely or not at all.

func (*CBK) Flush

func (e *CBK) Flush(w io.Writer) error

Flush pushes the remaining bytes stored into the buffer into the supplies Writer.

func (*CBK) Read

func (e *CBK) Read(r io.Reader, b []byte) (int, error)

Read reads the contents of the Reader to the byte array after decrypting with this Cipher.

func (*CBK) Reset

func (e *CBK) Reset() error

Reset resets the encryption keys and sets them to new random bytes.

func (*CBK) Shuffle

func (e *CBK) Shuffle(b []byte)

Shuffle will switch around the bytes in the array based on the Cipher bytes.

func (*CBK) Write

func (e *CBK) Write(w io.Writer, b []byte) (int, error)

Write writes the contents of the byte array to the Writer after encrypting with this Cipher.

type XOR

type XOR []byte

XOR is an alias for a byte array that acts as the XOR key data buffer.

func (XOR) BlockSize

func (x XOR) BlockSize() int

BlockSize returns the cipher's block size.

func (XOR) Decrypt

func (x XOR) Decrypt(dst, src []byte)

Decrypt preforms the XOR operation on the specified byte array using the cipher as the key.

func (XOR) Encrypt

func (x XOR) Encrypt(dst, src []byte)

Encrypt preforms the XOR operation on the specified byte array using the cipher as the key.

func (XOR) Operate

func (x XOR) Operate(b []byte)

Operate preforms the XOR operation on the specified byte array using the cipher as the key.

Directories

Path Synopsis
Package subtle is similar to the 'cipher/subtle', only needed for very specific crypto operations.
Package subtle is similar to the 'cipher/subtle', only needed for very specific crypto operations.

Jump to

Keyboard shortcuts

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