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 ¶
- func DecryptAesGcm(key, nonce, ciphertext []byte) (text string, err error)
- func DecryptChacha20poly1305(key, nonce, ciphertext []byte) (text string, err error)
- func EncryptAesGcm(key []byte, text string) (ciphertext []byte, nonce []byte, err error)
- func EncryptChacha20poly1305(key []byte, text string) (ciphertext []byte, nonce []byte, err error)
- type Decoder
- func (d *Decoder) DecryptRSA(ciphertext []byte) (text string, err error)
- func (d *Decoder) FromBase64RawStd(text string) ([]byte, error)
- func (d *Decoder) FromBase64RawURL(text string) ([]byte, error)
- func (d *Decoder) FromBase64Std(text string) ([]byte, error)
- func (d *Decoder) FromBase64URL(text string) ([]byte, error)
- type Encoder
- type HashAlgorithm
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecryptAesGcm ¶
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 ¶
DecryptChacha20poly1305 decrypts and authenticates the given message with ChaCha20-Poly1305 AEAD using the given 256-bit key and 96-bit nonce.
func EncryptAesGcm ¶
EncryptAesGcm encrypts and authenticates the given message with AES in GCM mode using the given 128, 192 or 256-bit key.
Types ¶
type Decoder ¶
type Decoder struct { PriKeyBlock *pem.Block HashAlg HashAlgorithm Err error }
Decoder - PEM-encoded block of data
func NewDecoder ¶
NewDecoder takes a PEM-encoded private key string as input and attempts to decode it.
func (*Decoder) DecryptRSA ¶
DecryptRSA decrypts the given message with RSA-OAEP and using SHA-256 (default) or SHA-512.
func (*Decoder) FromBase64RawStd ¶
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 ¶
FromBase64RawURL - decode the Base64-encoded string into binary data using the unpadded alternate base64 encoding defined in RFC 4648.
func (*Decoder) FromBase64Std ¶
FromBase64Std - decode the Base64-encoded string into binary data using the standard Base64 character set.
type Encoder ¶
type Encoder struct { PubKeyBlock *pem.Block HashAlg HashAlgorithm Err error }
Encoder - PEM-encoded block of data
func NewEncoder ¶
NewEncoder takes a PEM-encoded public key string as input and attempts to decode it.
func (*Encoder) EncryptRSA ¶
EncryptRSA encrypts the given message with RSA-OAEP and using SHA-256 (default) or SHA-512.
func (*Encoder) ToBase64RawStd ¶
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 ¶
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 ¶
ToBase64Std - encode the binary data into a Base64-encoded string using the standard Base64 character set.
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 )
Source Files ¶
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 |