Documentation ¶
Index ¶
- type SecureData
- func (s *SecureData) Decrypt(data []byte, passphrase string) ([]byte, error)
- func (s *SecureData) DecryptFile(filename string, passphrase string) ([]byte, error)
- func (s *SecureData) DecryptHex(data string, passphrase string) (string, error)
- func (s *SecureData) DecryptString(data string, passphrase string) (string, error)
- func (s *SecureData) DeriveKey(password, salt []byte) ([]byte, []byte, error)
- func (s *SecureData) Encrypt(data []byte, passphrase string) ([]byte, error)
- func (s *SecureData) EncryptFile(filename string, data []byte, passphrase string)
- func (s *SecureData) EncryptString(data string, passphrase string) (string, error)
- func (s *SecureData) FromHex(data []byte) ([]byte, error)
- func (s *SecureData) FromHexString(data string) ([]byte, error)
- func (s *SecureData) IsEncrypted(data string) int
- func (s *SecureData) IsEncryptedBytes(data []byte) int
- func (s *SecureData) ToHexString(data []byte) string
- func (s *SecureData) TryDecryptString(data string, passphrase string) (string, error)
- func (s *SecureData) TryEncryptString(data string, passphrase string) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SecureData ¶ added in v1.7.0
type SecureData struct {
Prefix []byte
}
func NewSecureData ¶ added in v1.7.0
func NewSecureData(prefix string) *SecureData
NewSecureData is used to securely read and write encrypted data
func (*SecureData) Decrypt ¶ added in v1.7.0
func (s *SecureData) Decrypt(data []byte, passphrase string) ([]byte, error)
Decrypt decrypt the data. The data should be stored with a 32 byte salt which is append at the end of the data
func (*SecureData) DecryptFile ¶ added in v1.7.0
func (s *SecureData) DecryptFile(filename string, passphrase string) ([]byte, error)
func (*SecureData) DecryptHex ¶ added in v1.7.0
func (s *SecureData) DecryptHex(data string, passphrase string) (string, error)
func (*SecureData) DecryptString ¶ added in v1.7.0
func (s *SecureData) DecryptString(data string, passphrase string) (string, error)
func (*SecureData) DeriveKey ¶ added in v1.7.0
func (s *SecureData) DeriveKey(password, salt []byte) ([]byte, []byte, error)
DeriveKey creates a secure key from a given password. It also accepts a salt which is used to increase the security of the key to prevent Rainbow tables attacks. If the salt is nil, then a secure salt will be generated using scrypt.
func (*SecureData) Encrypt ¶ added in v1.7.0
func (s *SecureData) Encrypt(data []byte, passphrase string) ([]byte, error)
Encrypt encrypts the data with a passphrase. Salt is used on the passphrase and stored in the last 32 bytes of the data (appended decrypted) Example: asdfadsfasdfasdfasdf<salt>
func (*SecureData) EncryptFile ¶ added in v1.7.0
func (s *SecureData) EncryptFile(filename string, data []byte, passphrase string)
func (*SecureData) EncryptString ¶ added in v1.7.0
func (s *SecureData) EncryptString(data string, passphrase string) (string, error)
EncryptString encryptes a string to a hex encoded string using a passphrase and salt. A prefix is also added to it (if defined)
func (*SecureData) FromHex ¶ added in v1.7.0
func (s *SecureData) FromHex(data []byte) ([]byte, error)
func (*SecureData) FromHexString ¶ added in v1.7.0
func (s *SecureData) FromHexString(data string) ([]byte, error)
func (*SecureData) IsEncrypted ¶ added in v1.7.0
func (s *SecureData) IsEncrypted(data string) int
IsEncrypted returns if the given data is encrypted or not. The data is encrypted if it starts with the encryption marker. If an empty string is used as the encryption prefix, then the it can not be reliably checked if the data is enrypted or not. 1 - data is encrypted 0 - data is not encrypted -1 - data encryption is unknown (could be encrypted or not)
func (*SecureData) IsEncryptedBytes ¶ added in v1.7.0
func (s *SecureData) IsEncryptedBytes(data []byte) int
IsEncryptedBytes returns if the given data is encrypted or not. The data is encrypted if it starts with the encryption marker. If an empty string is used as the encryption prefix, then the it can not be reliably checked if the data is enrypted or not. 1 - data is encrypted 0 - data is not encrypted -1 - data encryption is unknown (could be encrypted or not)
func (*SecureData) ToHexString ¶ added in v1.7.0
func (s *SecureData) ToHexString(data []byte) string
func (*SecureData) TryDecryptString ¶ added in v1.7.0
func (s *SecureData) TryDecryptString(data string, passphrase string) (string, error)
TryDecryptString tries to decrypt a string. If a encryption prefex string is used, then the data will only be decrypted if the input data has the prefix, otherwise it will be returned as is.
func (*SecureData) TryEncryptString ¶ added in v1.7.0
func (s *SecureData) TryEncryptString(data string, passphrase string) (string, error)
TryEncryptString encrypts a string only if it is not already encrypted