Documentation
¶
Overview ¶
Package crypto provides the cryptographic functions required within the SDK.
There are two kinds of decrypted data:
- Metadata means any small string data, typically file metadata, but also e.g. directory names.
- Data means file content.
Index ¶
- func DeriveKEKAndAuthFromPassword(password string, salt string) (*EncryptionKey, DerivedPassword, error)
- func DeriveMKAndAuthFromPassword(password string, salt string) (*MasterKey, DerivedPassword, error)
- func GenerateRandomBytes(length int) []byte
- func GenerateRandomString(length int) string
- func PublicKeyFromString(pubKey string) (*rsa.PublicKey, error)
- func RSAKeyPairFromStrings(privKey string, pubKey string) (*rsa.PrivateKey, *rsa.PublicKey, error)
- func RunSHA512(b []byte) []byte
- func V1Decrypt(data, key []byte) ([]byte, error)
- func V1DeriveMasterKeyAndDerivedPass(password string) (*MasterKey, DerivedPassword, error)
- func V2Hash(data []byte) string
- type AllKeysFailedError
- type AuthVersion
- type DerivedPassword
- type EncryptedString
- type EncryptionKey
- func MakeEncryptionKeyFromBytes(key [32]byte) (*EncryptionKey, error)
- func MakeEncryptionKeyFromStr(key string) (*EncryptionKey, error)
- func MakeEncryptionKeyFromUnknownStr(key string) (*EncryptionKey, error)
- func MakeNewFileKey(v FileEncryptionVersion) (*EncryptionKey, error)
- func NewEncryptionKey() (*EncryptionKey, error)
- func (key *EncryptionKey) DecryptData(data []byte) ([]byte, error)
- func (key *EncryptionKey) DecryptMeta(metadata EncryptedString) (string, error)
- func (key *EncryptionKey) EncryptData(data []byte) []byte
- func (key *EncryptionKey) EncryptMeta(metadata string) EncryptedString
- func (key *EncryptionKey) ToString() string
- func (key *EncryptionKey) ToStringWithVersion(v FileEncryptionVersion) string
- type FileEncryptionVersion
- type HMACKey
- type MasterKey
- type MasterKeys
- type MetaCrypter
- type MetadataEncryptionVersion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeriveKEKAndAuthFromPassword ¶ added in v0.0.5
func DeriveKEKAndAuthFromPassword(password string, salt string) (*EncryptionKey, DerivedPassword, error)
DeriveKEKAndAuthFromPassword returns a KEK and a DerivedPassword derived from the user password
func DeriveMKAndAuthFromPassword ¶ added in v0.0.5
func DeriveMKAndAuthFromPassword(password string, salt string) (*MasterKey, DerivedPassword, error)
DeriveMKAndAuthFromPassword returns a MasterKey and a DerivedPassword
func GenerateRandomBytes ¶ added in v0.0.5
GenerateRandomBytes generates a cryptographically secure random byte array
func GenerateRandomString ¶
GenerateRandomString generates a cryptographically secure random string based on a selection of alphanumerical characters.
func PublicKeyFromString ¶ added in v0.0.18
PublicKeyFromString returns a public key from a base64 encoded string
func RSAKeyPairFromStrings ¶ added in v0.0.5
RSAKeyPairFromStrings returns a private and public key pair from base64 encoded strings
func V1DeriveMasterKeyAndDerivedPass ¶ added in v0.0.22
func V1DeriveMasterKeyAndDerivedPass(password string) (*MasterKey, DerivedPassword, error)
for backwards compatibility with V1 only
Types ¶
type AllKeysFailedError ¶
type AllKeysFailedError struct {
Errors []error // errors thrown in the process
}
AllKeysFailedError denotes that no key passed to [DecryptMetadataAllKeys] worked.
func (*AllKeysFailedError) Error ¶
func (e *AllKeysFailedError) Error() string
type AuthVersion ¶ added in v0.0.22
type AuthVersion int
type DerivedPassword ¶ added in v0.0.5
type DerivedPassword string
DerivedPassword is derived from the user password, and used to authenticate the user to the backend
func V1HashPassword ¶ added in v0.0.22
func V1HashPassword(password string) DerivedPassword
for backwards compatibility with V1 only
type EncryptedString ¶
type EncryptedString string
EncryptedString denotes that a string is encrypted and can't be used meaningfully before being decrypted.
func NewEncryptedStringV2 ¶ added in v0.0.5
func NewEncryptedStringV2(encrypted []byte, nonce [12]byte) EncryptedString
NewEncryptedStringV2 creates a new EncryptedString with the v2 format
func NewEncryptedStringV3 ¶ added in v0.0.5
func NewEncryptedStringV3(encrypted []byte, nonce [12]byte) EncryptedString
NewEncryptedStringV3 creates a new EncryptedString with the v3 format
func PublicEncrypt ¶ added in v0.0.18
func PublicEncrypt(publicKey *rsa.PublicKey, data string) (EncryptedString, error)
PublicEncrypt encrypts data using a public key
type EncryptionKey ¶ added in v0.0.5
EncryptionKey is used to encrypt and decrypt data these keys are used as the v3 KEK, DEK and v2/v3 file Keys
func MakeEncryptionKeyFromBytes ¶ added in v0.0.5
func MakeEncryptionKeyFromBytes(key [32]byte) (*EncryptionKey, error)
MakeEncryptionKeyFromBytes returns a new encryption key from a 32 byte array
func MakeEncryptionKeyFromStr ¶ added in v0.0.5
func MakeEncryptionKeyFromStr(key string) (*EncryptionKey, error)
MakeEncryptionKeyFromStr returns a new encryption key from a 64 char hex encoded string
func MakeEncryptionKeyFromUnknownStr ¶ added in v0.0.5
func MakeEncryptionKeyFromUnknownStr(key string) (*EncryptionKey, error)
MakeEncryptionKeyFromUnknownStr returns a new encryption key from either a 32 character string or a 64 character hex encoded string
func MakeNewFileKey ¶ added in v0.0.13
func MakeNewFileKey(v FileEncryptionVersion) (*EncryptionKey, error)
MakeNewFileKey returns a new encryption key
func NewEncryptionKey ¶ added in v0.0.5
func NewEncryptionKey() (*EncryptionKey, error)
NewEncryptionKey generates a new encryption key using a random 32 byte array
func (*EncryptionKey) DecryptData ¶ added in v0.0.5
func (key *EncryptionKey) DecryptData(data []byte) ([]byte, error)
DecryptData decrypts file data using the encryption key returns the decrypted data, assumes that the nonce is the first 12 bytes
func (*EncryptionKey) DecryptMeta ¶ added in v0.0.5
func (key *EncryptionKey) DecryptMeta(metadata EncryptedString) (string, error)
DecryptMeta should be avoided, and Filen.DecryptMeta should be used instead
func (*EncryptionKey) EncryptData ¶ added in v0.0.5
func (key *EncryptionKey) EncryptData(data []byte) []byte
EncryptData encrypts file data using the encryption key generates a nonce and prepends it to the data
func (*EncryptionKey) EncryptMeta ¶ added in v0.0.5
func (key *EncryptionKey) EncryptMeta(metadata string) EncryptedString
EncryptMeta should be avoided, and Filen.EncryptMeta should be used instead
func (*EncryptionKey) ToString ¶ added in v0.0.5
func (key *EncryptionKey) ToString() string
ToString returns a 64 char hex encoded string representation of the encryption key
func (*EncryptionKey) ToStringWithVersion ¶ added in v0.0.22
func (key *EncryptionKey) ToStringWithVersion(v FileEncryptionVersion) string
type FileEncryptionVersion ¶ added in v0.0.22
type FileEncryptionVersion int
type HMACKey ¶ added in v0.0.15
type HMACKey [32]byte
HMACKey is a 256 bit key used as a generic hashing key any time we want a hash of a string
func MakeHMACKey ¶ added in v0.0.15
func MakeHMACKey(privateKey *rsa.PrivateKey) HMACKey
MakeHMACKey derives a 256 bit key from a private key this is to allow a single key to derivable from both V2 and V3 accounts
type MasterKey ¶ added in v0.0.5
type MasterKey struct { Bytes []byte DerivedBytes [32]byte // contains filtered or unexported fields }
MasterKey is a key used to encrypt and decrypt metadata in the v1 and v2 encryption schemes
func NewMasterKey ¶ added in v0.0.5
NewMasterKey creates a new MasterKey from a byte slice
func (*MasterKey) DecryptMeta ¶ added in v0.0.5
func (m *MasterKey) DecryptMeta(metadata EncryptedString) (string, error)
DecryptMeta should be avoided, and Filen.DecryptMeta should be used instead
func (*MasterKey) DecryptMetaV2 ¶ added in v0.0.5
func (m *MasterKey) DecryptMetaV2(metadata EncryptedString) (string, error)
DecryptMetaV2 should be avoided, and Filen.DecryptMeta should be used instead
func (*MasterKey) EncryptMeta ¶ added in v0.0.5
func (m *MasterKey) EncryptMeta(metadata string) EncryptedString
EncryptMeta should be avoided, and Filen.EncryptMeta should be used instead
type MasterKeys ¶ added in v0.0.5
type MasterKeys []MasterKey
MasterKeys is a slice of MasterKey, this is used by the V1 and V2 encryption schemes
func NewMasterKeys ¶ added in v0.0.5
func NewMasterKeys(encryptionKey MasterKey, stringKeys string) (MasterKeys, error)
NewMasterKeys creates a new MasterKeys slice
func (*MasterKeys) DecryptMeta ¶ added in v0.0.5
func (ms *MasterKeys) DecryptMeta(encrypted EncryptedString) (string, error)
DecryptMeta should be avoided, and Filen.DecryptMeta should be used instead, but this is necessary for RSA Keypair decryption
func (*MasterKeys) DecryptMetaV1 ¶ added in v0.0.5
func (ms *MasterKeys) DecryptMetaV1(metadata EncryptedString) (string, error)
DecryptMetaV1 should be avoided, and Filen.DecryptMeta should be used instead
func (*MasterKeys) DecryptMetaV2 ¶ added in v0.0.5
func (ms *MasterKeys) DecryptMetaV2(metadata EncryptedString) (string, error)
DecryptMetaV2 should be avoided, and Filen.DecryptMeta should be used instead
func (*MasterKeys) EncryptMeta ¶ added in v0.0.5
func (ms *MasterKeys) EncryptMeta(metadata string) EncryptedString
EncryptMeta should be avoided, and Filen.EncryptMeta should be used instead
type MetaCrypter ¶ added in v0.0.14
type MetaCrypter interface { EncryptMeta(metadata string) EncryptedString DecryptMeta(encrypted EncryptedString) (string, error) }
type MetadataEncryptionVersion ¶ added in v0.0.22
type MetadataEncryptionVersion int