encryption

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidBlockSize indicates block size <= 0.
	ErrInvalidBlockSize = errors.New("invalid block size")

	// ErrInvalidPKCS7Data indicates bad input to PKCS7 pad or unpad.
	ErrInvalidPKCS7Data = errors.New("invalid PKCS7 data (empty or not padded)")

	// ErrInvalidPKCS7Padding indicates PKCS7 unpad fails.
	ErrInvalidPKCS7Padding = errors.New("invalid padding on input")

	// ErrEmptyCiphertext indicates empty ciphertext.
	ErrEmptyCiphertext = errors.New("empty ciphertext")

	// ErrInvalidCiphertextSize indicates that the size of ciphertext is not a multiple of blocksize.
	ErrInvalidCiphertextSize = errors.New("invalid ciphertext size")

	// ErrInvalidKeySize indicates that the size of key is not 16 bytes
	ErrInvalidKeySize = errors.New("invalid key size")

	// ErrInvalidIVSize indicates that the size of iv is not 16 bytes
	ErrInvalidIVSize = errors.New("invalid iv size")
)

Functions

func AESDecrypt

func AESDecrypt(ciphertext []byte, key []byte, iv []byte) ([]byte, error)

AESDecrypt decrypts ciphertext with AES and returns plaintext

func AESEncrypt

func AESEncrypt(plaintext []byte, key []byte, iv []byte) ([]byte, error)

AESEncrypt returns ciphertext which is encrypted with AES from plaintext mode: CBC padding: PKCS7 key size: 16 bytes iv size: 16 bytes

func CheckKeyAndIVSize

func CheckKeyAndIVSize(key []byte, iv []byte) ([]byte, []byte, error)

CheckKeyAndIVSize requires that both key's size and iv's size must be 16 bytes

func PKCS7Padding

func PKCS7Padding(plaintext []byte, blockSize int) ([]byte, error)

PKCS7Padding pads bytes to the right of plaintext so that the length of plaintext after padding will be a multiple of blocksize(16 bytes for AES).

func PKCS7Unpadding

func PKCS7Unpadding(b []byte, blocksize int) ([]byte, error)

PKCS7Unpadding validates and unpads bytes from decrypted result b is the original data decrypted, including the padding bytes

Types

This section is empty.

Jump to

Keyboard shortcuts

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