Documentation ¶
Index ¶
- Constants
- type ICrypto
- type SCrypto
- func (c *SCrypto) Base64Decode(src []byte, maxLen int) []byte
- func (c *SCrypto) Base64Encode(src []byte, maxLen int) []byte
- func (c *SCrypto) DecryptFile(encryptedFilePath, key, iv, outputFilePath string) error
- func (c *SCrypto) EncryptFile(plainFilePath string, key, iv []byte) (string, error)
- func (c *SCrypto) Hex(src []byte, maxLen int) []byte
- func (c *SCrypto) NewDecryptWriteCloser(writeCloser io.WriteCloser, key, iv string) (*gcm.DecryptWriteCloser, error)
- func (c *SCrypto) NewEncryptReader(reader io.Reader, key, iv []byte) (*gcm.EncryptReader, error)
- func (c *SCrypto) Unhex(src []byte, maxLen int) []byte
Constants ¶
const ( // KeySize is the size of the encryption key in bytes KeySize = 32 // IVSize is the size of the IV in bytes IVSize = 12 // LegacyIVSize is the size of the IV in bytes for the legacy encryption scheme LegacyIVSize = 16 // AADSize is the size in bytes of the Additional Authenticated Data for the // GCM encryption AADSize = 16 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ICrypto ¶
type ICrypto interface { DecryptFile(encryptedFilePath, key, iv, outputFilePath string) error EncryptFile(plainFilePath string, key, iv []byte) (string, error) NewEncryptReader(reader io.Reader, key, iv []byte) (*gcm.EncryptReader, error) NewDecryptWriteCloser(writeCloser io.WriteCloser, key, iv string) (*gcm.DecryptWriteCloser, error) Hex(src []byte, maxLen int) []byte Unhex(src []byte, maxLen int) []byte Base64Encode(src []byte, maxLen int) []byte Base64Decode(src []byte, maxLen int) []byte }
ICrypto
type SCrypto ¶
type SCrypto struct{}
SCrypto is an implementor of ICrypto
func (*SCrypto) Base64Decode ¶
Base64Decode bytes
func (*SCrypto) Base64Encode ¶
Base64Encode bytes
func (*SCrypto) DecryptFile ¶
DecryptFile takes in an ecrypted file and decrypts it to the given output path based on the Key and IV. The Key and IV should be the hex and base64 encoded version
func (*SCrypto) EncryptFile ¶
EncryptFile takes in an open plaintext file and encrypts it to a temporary location based on the key and IV. It is up to the caller to ensure the encrypted file is deleted after it's used. The passed in key and iv should *NOT* be base64 encoded or hex encoded.
func (*SCrypto) NewDecryptWriteCloser ¶
func (c *SCrypto) NewDecryptWriteCloser(writeCloser io.WriteCloser, key, iv string) (*gcm.DecryptWriteCloser, error)
NewDecryptWriteCloser takes a io.WriteCloser and wraps it in a type that will decrypt Writes to the io.WriteCloser as they are written. The passed in key and iv should *NOT* be base64 encoded or hex encoded.
func (*SCrypto) NewEncryptReader ¶
NewEncryptReader takes in a Reader and wraps it in a type that will encrypt the Reader as its read. The passed in key and iv should *NOT* be base64 encoded or hex encoded.