encrypt

package
v0.0.0-...-503c688 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESDecryptWithCBC

func AESDecryptWithCBC(cryptStr, key []byte, iv []byte) ([]byte, error)

AESDecryptWithCBC decrypts data using AES with CBC mode.

func AESDecryptWithCFB

func AESDecryptWithCFB(cryptStr, key []byte, iv []byte) ([]byte, error)

AESDecryptWithCFB decrypts data using AES with CFB mode.

func AESDecryptWithCTR

func AESDecryptWithCTR(cryptedStr, key []byte, iv []byte) ([]byte, error)

AESDecryptWithCTR decrypts data using AES with CTR mode.

func AESDecryptWithECB

func AESDecryptWithECB(cryptStr, key []byte) ([]byte, error)

AESDecryptWithECB decrypts data using AES with ECB mode.

func AESDecryptWithOFB

func AESDecryptWithOFB(cipherStr []byte, key []byte, iv []byte) ([]byte, error)

AESDecryptWithOFB decrypts data using AES with OFB mode.

func AESEncryptWithCBC

func AESEncryptWithCBC(str, key []byte, iv []byte) ([]byte, error)

AESEncryptWithCBC encrypts data using AES with CBC mode.

func AESEncryptWithCFB

func AESEncryptWithCFB(cryptStr, key []byte, iv []byte) ([]byte, error)

AESEncryptWithCFB encrypts data using AES with CFB mode.

func AESEncryptWithCTR

func AESEncryptWithCTR(plainStr, key []byte, iv []byte) ([]byte, error)

AESEncryptWithCTR encrypts data using AES with CTR mode.

func AESEncryptWithECB

func AESEncryptWithECB(str, key []byte) ([]byte, error)

AESEncryptWithECB encrypts data using AES with ECB mode.

func AESEncryptWithOFB

func AESEncryptWithOFB(plainStr []byte, key []byte, iv []byte) ([]byte, error)

AESEncryptWithOFB encrypts data using AES with OFB mode.

func DeriveKeyMySQL

func DeriveKeyMySQL(key []byte, blockSize int) []byte

DeriveKeyMySQL derives the encryption key from a password in MySQL algorithm. See https://security.stackexchange.com/questions/4863/mysql-aes-encrypt-key-length.

func PKCS7Pad

func PKCS7Pad(data []byte, blockSize int) ([]byte, error)

PKCS7Pad pads data using PKCS7. See hhttp://tools.ietf.org/html/rfc2315.

func PKCS7Unpad

func PKCS7Unpad(data []byte, blockSize int) ([]byte, error)

PKCS7Unpad unpads data using PKCS7. See http://tools.ietf.org/html/rfc2315.

func SQLDecode

func SQLDecode(str string, password string) (string, error)

SQLDecode Function to handle the decode() function

func SQLEncode

func SQLEncode(cryptStr string, password string) (string, error)

SQLEncode Function to handle the encode() function

Types

type CtrCipher

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

CtrCipher encrypting data using AES in counter mode

func NewCtrCipher

func NewCtrCipher() (ctr *CtrCipher, err error)

NewCtrCipher return a CtrCipher using the default encrypt block size

func NewCtrCipherWithBlockSize

func NewCtrCipherWithBlockSize(encryptBlockSize int64) (ctr *CtrCipher, err error)

NewCtrCipherWithBlockSize return a CtrCipher with the encrypt block size

type Reader

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

Reader implements an io.ReadAt, reading from the input source after decrypting.

func NewReader

func NewReader(r io.ReaderAt, ctrCipher *CtrCipher) *Reader

NewReader returns a new Reader which can read from the input source after decrypting.

func (*Reader) ReadAt

func (r *Reader) ReadAt(p []byte, off int64) (n int, err error)

ReadAt implements the io.ReadAt interface.

type Writer

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

Writer implements an io.WriteCloser, it encrypt data using AES before writing to the underlying object.

func NewWriter

func NewWriter(w io.WriteCloser, ctrCipher *CtrCipher) *Writer

NewWriter returns a new Writer which encrypt data using AES before writing to the underlying object.

func (*Writer) AvailableSize

func (w *Writer) AvailableSize() int

AvailableSize returns how many bytes are unused in the buffer.

func (*Writer) Buffered

func (w *Writer) Buffered() int

Buffered returns the number of bytes that have been written into the current buffer.

func (*Writer) Close

func (w *Writer) Close() (err error)

Close implements the io.Closer interface.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush writes all the buffered data to the underlying object.

func (*Writer) GetCache

func (w *Writer) GetCache() []byte

GetCache returns the byte slice that holds the data not flushed to disk.

func (*Writer) GetCacheDataOffset

func (w *Writer) GetCacheDataOffset() int64

GetCacheDataOffset return the user data offset in cache.

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write implements the io.Writer interface.

Jump to

Keyboard shortcuts

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