Documentation ¶
Index ¶
- func CompressAndEncrypt(password string, plainText string, zLevel int) (string, error)
- func CompressAndEncryptBytes(password string, plainText []byte, zLevel int) (string, error)
- func Decrypt(password string, base64CipherText string) (string, error)
- func DecryptBytes(password string, base64CipherText string) ([]byte, error)
- func Encrypt(password string, plainText string) (string, error)
- func EncryptBytes(password string, plainText []byte) (string, error)
- func SetVariant(variant *base64.Encoding)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompressAndEncrypt ¶ added in v0.2.1
This function receives a password and a plain text (in string form), and a level for compression (from 1 to 19) and produces a string with their encryption, compressing the plaintext if possible. Returns it, or an eventual error, and closes all related resources.
More in detail:
- generates a key derived from the password, using SCrypt;
- converts the plain text to a byte array;
- compresses this array using ZStd and the given compression level;
- if the data aren't compressible, keeps the uncompressed data;
- encrypts the data with the key using XChaCha20-Poly1305, with an authentication tag.
The output string is the output data, Base64-encoded. It contains:
- an header with the format version and information on whether data were encrypted or not;
- an array of random bytes, used as the Salt for SCrypt and IV for XChaCha;
- encrypted data;
- an authentication tag, part of the output of XChaCha20-Poly1305, used to verify the integrity when decrypting.
func CompressAndEncryptBytes ¶ added in v1.1.0
This function receives a password, a byte array, and a level for compression (from 1 to 19) and produces a string with their encryption, compressing the byte array if possible. Returns it, or an eventual error, and closes all related resources.
More in detail:
- generates a key derived from the password, using SCrypt;
- compresses the byte array using ZStd and the given compression level;
- if the data aren't compressible, keeps the uncompressed data;
- encrypts the data with the key using XChaCha20-Poly1305, with an authentication tag.
The output string is the output data, Base64-encoded. It contains:
- an header with the format version and information on whether data were encrypted or not;
- an array of random bytes, used as the Salt for SCrypt and IV for XChaCha;
- encrypted data;
- an authentication tag, part of the output of XChaCha20-Poly1305, used to verify the integrity when decrypting.
func Decrypt ¶ added in v0.2.1
This function receives a password and a cypher text (as produced by one of the Encrypt* methods) and decodes the original plaintext (if the password is the one used for encryption).
It will return it or an eventual error, and closes all related resources. XChaCha20-Poly1305's authentication tag is used to detect any decryption error. It also transparently decompress data, if needed.
func DecryptBytes ¶ added in v1.1.0
This function receives a password and a cypher text (as produced by one of the *EncryptBytes methods) and decodes the original plaintext (if the password is the one used for encryption).
It will return it or an eventual error, and closes all related resources. XChaCha20-Poly1305's authentication tag is used to detect any decryption error. It also transparently decompress data, if needed.
func Encrypt ¶ added in v0.2.1
This function receives a password and a plain text (in string form) and produces a string with their encryption. Returns it, or an eventual error, and closes all related resources.
More in detail:
- generates a key derived from the password, using SCrypt;
- converts the plain text to a byte array;
- encrypts the data with the key using XChaCha20-Poly1305, with an authentication tag.
No compression is performed.
The output string is the output data, Base64-encoded. It contains:
- an header with the format version and information on whether data were encrypted or not;
- an array of random bytes, used as the Salt for SCrypt and IV for XChaCha;
- encrypted data;
- an authentication tag, part of the output of XChaCha20-Poly1305, used to verify the integrity when decrypting.
func EncryptBytes ¶ added in v1.1.0
This function receives a password and a a byte array and produces a string with their encryption. Returns it, or an eventual error, and closes all related resources.
More in detail:
- generates a key derived from the password, using SCrypt;
- encrypts the data with the key using XChaCha20-Poly1305, with an authentication tag.
No compression is performed.
The output string is the output data, Base64-encoded. It contains:
- an header with the format version and information on whether data were encrypted or not;
- an array of random bytes, used as the Salt for SCrypt and IV for XChaCha;
- encrypted data;
- an authentication tag, part of the output of XChaCha20-Poly1305, used to verify the integrity when decrypting.
func SetVariant ¶ added in v1.1.0
Sets a Base64 variant, for example base64.URLEncoding for URL_safe encoding.
Types ¶
This section is empty.