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 DecryptAesGcmWithNonceAppended(key, ciphertext []byte) (text string, err error)
- func DecryptByteChacha20poly1305(key, nonce, ciphertext []byte) (plaintext []byte, err error)
- func DecryptByteChacha20poly1305WithNonceAppended(key, ciphertext []byte) (plaintext []byte, err error)
- func DecryptByteXChacha20poly1305(key, nonce, ciphertext []byte) (plaintext []byte, err error)
- func DecryptByteXChacha20poly1305WithNonceAppended(key, ciphertext []byte) (plaintext []byte, err error)
- func DecryptChacha20poly1305(key, nonce, ciphertext []byte) (text string, err error)
- func DecryptChacha20poly1305WithNonceAppended(key, ciphertext []byte) (text string, err error)
- func DecryptXChacha20poly1305(key, nonce, ciphertext []byte) (text string, err error)
- func DecryptXChacha20poly1305WithNonceAppended(key, ciphertext []byte) (text string, err error)
- func EncryptAesGcm(key []byte, text string) (ciphertext []byte, nonce []byte, err error)
- func EncryptAesGcmWithNonceAppended(key []byte, text string) (ciphertext []byte, err error)
- func EncryptByteChacha20poly1305(key []byte, input []byte) (ciphertext []byte, nonce []byte, err error)
- func EncryptByteChacha20poly1305WithNonceAppended(key []byte, input []byte) (ciphertext []byte, err error)
- func EncryptByteXChacha20poly1305(key []byte, input []byte) (ciphertext []byte, nonce []byte, err error)
- func EncryptByteXChacha20poly1305WithNonceAppended(key []byte, input []byte) (ciphertext []byte, err error)
- func EncryptChacha20poly1305(key []byte, text string) (ciphertext []byte, nonce []byte, err error)
- func EncryptChacha20poly1305WithNonceAppended(key []byte, text string) (ciphertext []byte, err error)
- func EncryptXChacha20poly1305(key []byte, text string) (ciphertext []byte, nonce []byte, err error)
- func EncryptXChacha20poly1305WithNonceAppended(key []byte, text string) (ciphertext []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 DecryptAesGcmWithNonceAppended ¶ added in v0.0.10
DecryptAesGcmWithNonceAppended decrypts and authenticates the given message with AES in GCM mode using the given 128, 192 or 256-bit key. It expects the ciphertext to have the nonce appended.
func DecryptByteChacha20poly1305 ¶ added in v0.0.11
DecryptByteChacha20poly1305 decrypts and authenticates the given ciphertext with ChaCha20-Poly1305 AEAD using the given 256-bit key and 96-bit nonce.
func DecryptByteChacha20poly1305WithNonceAppended ¶ added in v0.0.11
func DecryptByteChacha20poly1305WithNonceAppended(key, ciphertext []byte) (plaintext []byte, err error)
DecryptByteChacha20poly1305WithNonceAppended decrypts and authenticates the given ciphertext with ChaCha20-Poly1305 AEAD using the given 256-bit key and 96-bit nonce. It expects the ciphertext along with the nonce [ciphertext = nonce + ciphertext].
func DecryptByteXChacha20poly1305 ¶ added in v0.0.11
DecryptByteXChacha20poly1305 decrypts and authenticates the given ciphertext with XChaCha20-Poly1305 AEAD using the given 256-bit key and 192-bit nonce.
func DecryptByteXChacha20poly1305WithNonceAppended ¶ added in v0.0.11
func DecryptByteXChacha20poly1305WithNonceAppended(key, ciphertext []byte) (plaintext []byte, err error)
DecryptByteXChacha20poly1305WithNonceAppended decrypts and authenticates the given ciphertext with XChaCha20-Poly1305 AEAD using the given 256-bit key and 192-bit nonce. It expects the ciphertext along with the nonce [ciphertext = nonce + ciphertext].
func DecryptChacha20poly1305 ¶
DecryptChacha20poly1305 decrypts and authenticates the given ciphertext with ChaCha20-Poly1305 AEAD using the given 256-bit key and 96-bit nonce.
func DecryptChacha20poly1305WithNonceAppended ¶ added in v0.0.10
DecryptChacha20poly1305WithNonceAppended decrypts and authenticates the given ciphertext with ChaCha20-Poly1305 AEAD using the given 256-bit key and 96-bit nonce. It expects the ciphertext along with the nonce [ciphertext = nonce + ciphertext].
func DecryptXChacha20poly1305 ¶ added in v0.0.10
DecryptXChacha20poly1305 decrypts and authenticates the given ciphertext with XChaCha20-Poly1305 AEAD using the given 256-bit key and 192-bit nonce.
func DecryptXChacha20poly1305WithNonceAppended ¶ added in v0.0.10
DecryptXChacha20poly1305WithNonceAppended decrypts and authenticates the given ciphertext with XChaCha20-Poly1305 AEAD using the given 256-bit key and 192-bit nonce. It expects the ciphertext along with the nonce [ciphertext = nonce + ciphertext].
func EncryptAesGcm ¶
EncryptAesGcm encrypts and authenticates the given message with AES in GCM mode using the given 128, 192 or 256-bit key.
func EncryptAesGcmWithNonceAppended ¶ added in v0.0.10
EncryptAesGcmWithNonceAppended encrypts and authenticates the given message with AES in GCM mode using the given 128, 192 or 256-bit key. It appends the ciphertext to the nonce.
func EncryptByteChacha20poly1305 ¶ added in v0.0.11
func EncryptByteChacha20poly1305(key []byte, input []byte) (ciphertext []byte, nonce []byte, err error)
EncryptByteChacha20poly1305 encrypts and authenticates the given message (bytes) with ChaCha20-Poly1305 AEAD using the given 256-bit key and 96-bit nonce.
func EncryptByteChacha20poly1305WithNonceAppended ¶ added in v0.0.11
func EncryptByteChacha20poly1305WithNonceAppended(key []byte, input []byte) (ciphertext []byte, err error)
EncryptByteChacha20poly1305WithNonceAppended encrypts and authenticates the given message (bytes) with ChaCha20-Poly1305 AEAD using the given 256-bit key and 96-bit nonce. It appends the ciphertext to the nonce [ciphertext = nonce + ciphertext].
func EncryptByteXChacha20poly1305 ¶ added in v0.0.11
func EncryptByteXChacha20poly1305(key []byte, input []byte) (ciphertext []byte, nonce []byte, err error)
EncryptByteXChacha20poly1305 encrypts and authenticates the given message (bytes) with XChaCha20-Poly1305 AEAD using the given 256-bit key and 192-bit nonce.
func EncryptByteXChacha20poly1305WithNonceAppended ¶ added in v0.0.11
func EncryptByteXChacha20poly1305WithNonceAppended(key []byte, input []byte) (ciphertext []byte, err error)
EncryptByteXChacha20poly1305WithNonceAppended encrypts and authenticates the given message (bytes) with XChaCha20-Poly1305 AEAD using the given 256-bit key and 192-bit nonce. It appends the ciphertext to the nonce [ciphertext = nonce + ciphertext].
func EncryptChacha20poly1305 ¶
EncryptChacha20poly1305 encrypts and authenticates the given message (string) with ChaCha20-Poly1305 AEAD using the given 256-bit key and 96-bit nonce.
func EncryptChacha20poly1305WithNonceAppended ¶ added in v0.0.10
func EncryptChacha20poly1305WithNonceAppended(key []byte, text string) (ciphertext []byte, err error)
EncryptChacha20poly1305WithNonceAppended encrypts and authenticates the given message (string) with ChaCha20-Poly1305 AEAD using the given 256-bit key and 96-bit nonce. It appends the ciphertext to the nonce [ciphertext = nonce + ciphertext].
func EncryptXChacha20poly1305 ¶ added in v0.0.10
EncryptXChacha20poly1305 encrypts and authenticates the given message (string) with XChaCha20-Poly1305 AEAD using the given 256-bit key and 192-bit nonce.
func EncryptXChacha20poly1305WithNonceAppended ¶ added in v0.0.10
func EncryptXChacha20poly1305WithNonceAppended(key []byte, text string) (ciphertext []byte, err error)
EncryptXChacha20poly1305WithNonceAppended encrypts and authenticates the given message (string) with XChaCha20-Poly1305 AEAD using the given 256-bit key and 192-bit nonce. It appends the ciphertext to the nonce [ciphertext = nonce + ciphertext].
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 |
xchacha20poly1305
Package main - example usage of XChaCha20-Poly1305 encryption - decryption
|
Package main - example usage of XChaCha20-Poly1305 encryption - decryption |