crypt

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 10 Imported by: 2

README

crypt

Package crypt provides functions for encrypting and decrypting data using various cryptographic algorithms, including RSA and AES.

This package is designed to simplify the process of securely encrypting and decrypting data following industry standards. It includes functions for key generation, encryption, and decryption using well-established cryptographic primitives.

Usage

Generate RSA Keys

256-byte
openssl genpkey -algorithm RSA -out private-key.pem -pkeyopt rsa_keygen_bits:2048
openssl rsa -in private-key.pem -pubout -out public-key.pem
384-byte
openssl genpkey -algorithm RSA -out private-key.pem -pkeyopt rsa_keygen_bits:3072
openssl rsa -in private-key.pem -pubout -out public-key.pem
512-byte
openssl genpkey -algorithm RSA -out private-key.pem -pkeyopt rsa_keygen_bits:4096
openssl rsa -in private-key.pem -pubout -out public-key.pem

LICENSE

license

Documentation

Overview

Package crypt provides functions for encrypting and decrypting data using various cryptographic algorithms, including RSA and AES.

This package is designed to simplify the process of securely encrypting and decrypting data following industry standards. It includes functions for key generation, encryption, and decryption using well-established cryptographic primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptAesGcm

func DecryptAesGcm(key, nonce, ciphertext []byte) (text string, err error)

DecryptAesGcm decrypts and authenticates the given message with AES in GCM mode using the given 128, 192 or 256-bit key and 96-bit nonce.

func DecryptChacha20poly1305

func DecryptChacha20poly1305(key, nonce, ciphertext []byte) (text string, err error)

DecryptChacha20poly1305 decrypts and authenticates the given message with ChaCha20-Poly1305 AEAD using the given 256-bit key and 96-bit nonce.

func EncryptAesGcm

func EncryptAesGcm(key []byte, text string) (ciphertext []byte, nonce []byte, err error)

EncryptAesGcm encrypts and authenticates the given message with AES in GCM mode using the given 128, 192 or 256-bit key.

func EncryptChacha20poly1305

func EncryptChacha20poly1305(key []byte, text string) (ciphertext []byte, nonce []byte, err error)

EncryptChacha20poly1305 encrypts and authenticates the given message with ChaCha20-Poly1305 AEAD using the given 256-bit key.

Types

type Decoder

type Decoder struct {
	PriKeyBlock *pem.Block
	HashAlg     HashAlgorithm
	Err         error
}

Decoder - PEM-encoded block of data

func NewDecoder

func NewDecoder(privateKeyPEM string) *Decoder

NewDecoder takes a PEM-encoded private key string as input and attempts to decode it.

func (*Decoder) DecryptRSA

func (d *Decoder) DecryptRSA(ciphertext []byte) (text string, err error)

DecryptRSA decrypts the given message with RSA-OAEP and using SHA-256 (default) or SHA-512.

func (*Decoder) FromBase64RawStd

func (d *Decoder) FromBase64RawStd(text string) ([]byte, error)

FromBase64RawStd - decode the Base64-encoded string into binary data using the standard raw, unpadded Base64 encoding character set, as defined in RFC 4648 section 3.2.

func (*Decoder) FromBase64RawURL

func (d *Decoder) FromBase64RawURL(text string) ([]byte, error)

FromBase64RawURL - decode the Base64-encoded string into binary data using the unpadded alternate base64 encoding defined in RFC 4648.

func (*Decoder) FromBase64Std

func (d *Decoder) FromBase64Std(text string) ([]byte, error)

FromBase64Std - decode the Base64-encoded string into binary data using the standard Base64 character set.

func (*Decoder) FromBase64URL

func (d *Decoder) FromBase64URL(text string) ([]byte, error)

FromBase64URL - decode the Base64-encoded string into binary data using the alternate base64 encoding defined in RFC 4648.

type Encoder

type Encoder struct {
	PubKeyBlock *pem.Block
	HashAlg     HashAlgorithm
	Err         error
}

Encoder - PEM-encoded block of data

func NewEncoder

func NewEncoder(publicKeyPEM string) *Encoder

NewEncoder takes a PEM-encoded public key string as input and attempts to decode it.

func (*Encoder) EncryptRSA

func (e *Encoder) EncryptRSA(text string) (ciphertext []byte, err error)

EncryptRSA encrypts the given message with RSA-OAEP and using SHA-256 (default) or SHA-512.

func (*Encoder) ToBase64RawStd

func (e *Encoder) ToBase64RawStd(text []byte) string

ToBase64RawStd - encode the binary data into a Base64-encoded string using the standard raw, unpadded base64 encoding character set, as defined in RFC 4648 section 3.2. This is the same as StdEncoding but omits the padding characters.

func (*Encoder) ToBase64RawURL

func (e *Encoder) ToBase64RawURL(text []byte) string

ToBase64RawURL - encode the binary data into a Base64-encoded string using the unpadded alternate base64 encoding defined in RFC 4648 suitable for URLs and file names. It omits the padding characters.

func (*Encoder) ToBase64Std

func (e *Encoder) ToBase64Std(text []byte) string

ToBase64Std - encode the binary data into a Base64-encoded string using the standard Base64 character set.

func (*Encoder) ToBase64URL

func (e *Encoder) ToBase64URL(text []byte) string

ToBase64URL - encode the binary data into a Base64-encoded string using the alternate base64 encoding defined in RFC 4648 suitable for URLs and file names.

type HashAlgorithm

type HashAlgorithm int

HashAlgorithm enum for selecting the hash algorithm.

const (
	// SHA256 selects SHA-256 as the hash algorithm.
	SHA256 HashAlgorithm = iota
	// SHA512 selects SHA-512 as the hash algorithm.
	SHA512
)

Directories

Path Synopsis
_example
aes
Package main - example usage of AES encryption - decryption
Package main - example usage of AES encryption - decryption
chacha20poly1305
Package main - example usage of chacha20poly1305 encryption - decryption
Package main - example usage of chacha20poly1305 encryption - decryption
hashing
Package main - example implementation of different hashing algorithms
Package main - example implementation of different hashing algorithms
rsa
Package main - example usage of RSA encryption - decryption
Package main - example usage of RSA encryption - decryption

Jump to

Keyboard shortcuts

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