Documentation ¶
Overview ¶
Package abcrypt implements the abcrypt encrypted data format.
Example ¶
ciphertext := abcrypt.EncryptWithParams([]byte(data), []byte(passphrase), 32, 3, 4) fmt.Printf("ciphertext and input data are different: %v\n", !slices.Equal(ciphertext, []byte(data))) plaintext, err := abcrypt.Decrypt(ciphertext, []byte(passphrase)) if err != nil { log.Fatal(err) } fmt.Printf("plaintext and input data are identical: %v\n", slices.Equal(plaintext, []byte(data)))
Output: ciphertext and input data are different: true plaintext and input data are identical: true
Index ¶
- Constants
- Variables
- func Decrypt(ciphertext, passphrase []byte) ([]byte, error)
- func Encrypt(plaintext, passphrase []byte) []byte
- func EncryptWithParams(plaintext, passphrase []byte, memoryCost, timeCost uint32, parallelism uint8) []byte
- type Decryptor
- type Encryptor
- type InvalidHeaderMACError
- type InvalidMACError
- type Params
- type UnknownVersionError
Examples ¶
Constants ¶
const HeaderSize = 140
HeaderSize is the number of bytes of the header.
const TagSize = chacha20poly1305.Overhead
TagSize is the number of bytes of the MAC (authentication tag) of the ciphertext.
Variables ¶
var ErrInvalidLength = errors.New("abcrypt: encrypted data is shorter than 156 bytes")
ErrInvalidLength represents an error due to the encrypted data was shorter than 156 bytes.
var ErrInvalidMagicNumber = errors.New("abcrypt: invalid magic number")
ErrInvalidMagicNumber represents an error due to the magic number (file signature) was invalid.
Functions ¶
func Decrypt ¶ added in v0.1.2
Decrypt decrypts the ciphertext and returns the plaintext.
This is a convenience function for using NewDecryptor and Decryptor.Decrypt.
func Encrypt ¶ added in v0.1.2
Encrypt encrypts the plaintext and returns the ciphertext.
This uses the recommended Argon2 parameters.
This is a convenience function for using NewEncryptor and Encryptor.Encrypt.
func EncryptWithParams ¶ added in v0.1.2
func EncryptWithParams(plaintext, passphrase []byte, memoryCost, timeCost uint32, parallelism uint8) []byte
EncryptWithParams encrypts the plaintext with the given Argon2 parameters and returns the ciphertext.
This is a convenience function for using NewEncryptorWithParams and Encryptor.Encrypt.
Types ¶
type Decryptor ¶
type Decryptor struct {
// contains filtered or unexported fields
}
Decryptor represents a decryptor for the abcrypt encrypted data format.
Example ¶
dataEnc, err := os.ReadFile("testdata/data.txt.abcrypt") if err != nil { log.Fatal(err) } fmt.Printf("input data size: %v B\n", len(dataEnc)) cipher, err := abcrypt.NewDecryptor(dataEnc, []byte(passphrase)) if err != nil { log.Fatal(err) } fmt.Printf("expected output size: %v B\n", cipher.OutLen()) plaintext, err := cipher.Decrypt() if err != nil { log.Fatal(err) } fmt.Printf("decrypted data size: %v B\n", len(plaintext))
Output: input data size: 170 B expected output size: 14 B decrypted data size: 14 B
func NewDecryptor ¶
NewDecryptor creates a new Decryptor.
type Encryptor ¶
type Encryptor struct {
// contains filtered or unexported fields
}
Encryptor represents an encryptor for the abcrypt encrypted data format.
Example ¶
fmt.Printf("input data size: %v B\n", len(data)) cipher := abcrypt.NewEncryptorWithParams([]byte(data), []byte(passphrase), 32, 3, 4) fmt.Printf("expected output size: %v B\n", cipher.OutLen()) ciphertext := cipher.Encrypt() fmt.Printf("encrypted data size: %v B\n", len(ciphertext))
Output: input data size: 14 B expected output size: 170 B encrypted data size: 170 B
func NewEncryptor ¶
NewEncryptor creates a new Encryptor.
This uses the recommended Argon2 parameters.
func NewEncryptorWithParams ¶
func NewEncryptorWithParams(plaintext, passphrase []byte, memoryCost, timeCost uint32, parallelism uint8) *Encryptor
NewEncryptorWithParams creates a new Encryptor with the given Argon2 parameters.
type InvalidHeaderMACError ¶ added in v0.2.0
type InvalidHeaderMACError struct { // MAC represents the obtained MAC of the header. MAC [64]byte }
InvalidHeaderMACError represents an error due to the MAC (authentication tag) of the header was invalid.
func (*InvalidHeaderMACError) Error ¶ added in v0.2.0
func (e *InvalidHeaderMACError) Error() string
Error returns a string representation of an InvalidHeaderMACError.
type InvalidMACError ¶
type InvalidMACError struct { // Err represents a wrapped error. Err error }
InvalidMACError represents an error due to the MAC (authentication tag) of the ciphertext was invalid.
func (*InvalidMACError) Error ¶
func (e *InvalidMACError) Error() string
Error returns a string representation of an InvalidMACError.
func (*InvalidMACError) Unwrap ¶
func (e *InvalidMACError) Unwrap() error
Unwrap returns the underlying error of an InvalidMACError.
type Params ¶
type Params struct { // MemoryCost represents memory size in KiB. MemoryCost uint32 `json:"memoryCost"` // TimeCost represents the number of iterations. TimeCost uint32 `json:"timeCost"` // Parallelism represents the degree of parallelism. Parallelism uint32 `json:"parallelism"` }
Params represents the Argon2 parameters used for the encrypted data.
Example ¶
ciphertext, err := os.ReadFile("testdata/data.txt.abcrypt") if err != nil { log.Fatal(err) } params, err := abcrypt.NewParams(ciphertext) if err != nil { log.Fatal(err) } fmt.Printf("memoryCost: %v\n", params.MemoryCost) fmt.Printf("timeCost: %v\n", params.TimeCost) fmt.Printf("parallelism: %v\n", params.Parallelism)
Output: memoryCost: 32 timeCost: 3 parallelism: 4
type UnknownVersionError ¶
type UnknownVersionError struct { // Version represents the obtained version number. Version byte }
UnknownVersionError represents an error due to the version was the unrecognized abcrypt version number.
func (*UnknownVersionError) Error ¶
func (e *UnknownVersionError) Error() string
Error returns a string representation of an UnknownVersionError.
Directories ¶
Path | Synopsis |
---|---|
Package examples contains sample applications for the module.
|
Package examples contains sample applications for the module. |
decrypt
Decrypt is an example of decrypting a file from the abcrypt encrypted data format.
|
Decrypt is an example of decrypting a file from the abcrypt encrypted data format. |
encrypt
Encrypt is an example of encrypting a file to the abcrypt encrypted data format.
|
Encrypt is an example of encrypting a file to the abcrypt encrypted data format. |
info
Info is an example of reading the Argon2 parameters from a file.
|
Info is an example of reading the Argon2 parameters from a file. |