crypto

package
v0.0.0-...-4743043 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAESMode              = errors.New("invalid AES encryption mode")
	ErrCiphertextTooShortToDecrypt = errors.New("ciphertext is too short to decrypt")
	ErrCiphertextIsEmpty           = errors.New("cipher text is empty")
	ErrCiphertextIsNotBlockAligned = errors.New("ciphertext is not block-aligned")
)

errors

Functions

func GenerateRSAKey

func GenerateRSAKey(size int) (*rsa.PrivateKey, error)

Generates a new RSA key by the given size

func HMAC

func HMAC(key []byte, params ...[]byte) []byte

Calculates the HMAC of params by the given key

func HMACEqual

func HMACEqual(mac1, mac2 []byte) bool

Compares two hmac parameters

Types

type AES

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

AES implementation for symmetric cryptography

func NewAES

func NewAES(mode AESMode) *AES

NewAES returns a new instance of AES implementation

func (*AES) Decrypt

func (a *AES) Decrypt(cipherBytes, key []byte) ([]byte, error)

Decrypts the ciphertext bytes by the given key

func (*AES) Encrypt

func (a *AES) Encrypt(plainBytes, key []byte) ([]byte, error)

Encrypts a byte array by the given key

type AESMode

type AESMode uint

AES mode type

const (
	AES_CBC AESMode = iota
)

list of supported AES mode

type Asymmetric

type Asymmetric interface {
	Decrypt(cipher []byte) ([]byte, error)
	GetPublicKey() []byte
}

The asymmetric cryptography interface This type of cryptography uses to decrypt the encrypted message from the client in the handshaking process

type RSACrypto

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

An implementation of RSA for asymmetric cryptography

func NewRSA

func NewRSA(keySize int) (*RSACrypto, error)

Returns a new instance of RSA implementation by generating a new key

func NewRSAFromBytes

func NewRSAFromBytes(pk []byte) (*RSACrypto, error)

Returns a new instance of RSA implementation by the given private key bytes

func NewRSAFromPK

func NewRSAFromPK(key *rsa.PrivateKey) *RSACrypto

Returns a new instance of RSA implementation by the given private key

func (*RSACrypto) Decrypt

func (c *RSACrypto) Decrypt(cipher []byte) ([]byte, error)

Decrypts cipher

func (*RSACrypto) GetPublicKey

func (c *RSACrypto) GetPublicKey() []byte

Returns public key bytes

type RSAEncryptor

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

func NewRSAEncryptorFromPK

func NewRSAEncryptorFromPK(key *rsa.PublicKey) *RSAEncryptor

func (*RSAEncryptor) Encrypt

func (c *RSAEncryptor) Encrypt(payload []byte) ([]byte, error)

type Symmetric

type Symmetric interface {
	Encrypt(p []byte, key []byte) ([]byte, error)
	Decrypt(c []byte, key []byte) ([]byte, error)
}

The symmetric cryptography interface This type of cryptography uses to encrypt messages for the client & decrypt the client packets after a success handshake

Jump to

Keyboard shortcuts

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