Documentation
¶
Index ¶
- Constants
- func ComputeKeyFileHash(keyData string) (string, error)
- func Decrypt(encrypted []byte, opts DecryptOptions) ([]byte, error)
- func DecryptFile(srcPath, dstPath string, opts DecryptOptions) error
- func DecryptReader(r io.Reader, w io.Writer, opts StreamDecryptOptions) error
- func DecryptStreamBytes(data []byte, opts StreamDecryptOptions) ([]byte, error)
- func Encrypt(data []byte, opts EncryptOptions) ([]byte, error)
- func EncryptAuto(data []byte, opts AutoEncryptOptions) ([]byte, error)
- func EncryptFileStream(srcPath, dstPath string, opts StreamEncryptOptions) error
- func EncryptReader(r io.Reader, w io.Writer, opts StreamEncryptOptions) error
- func EncryptStreamBytes(data []byte, opts StreamEncryptOptions) ([]byte, error)
- func GenerateKeyData() (string, error)
- func GenerateKeyDataWithOptions(opts KeyFileOptions) (string, error)
- func IsCryptoErrorCode(err error, code ErrorCode) bool
- func IsEncryptedData(data []byte, profile Profile) bool
- func IsStreamingEncryption(t EncryptionType) bool
- type AutoEncryptOptions
- type CryptoError
- type DecryptOptions
- type EncryptOptions
- type EncryptionType
- type ErrorCode
- type KeyFile
- type KeyFileOptions
- type Profile
- type Progress
- type ProgressPhase
- type StreamDecryptOptions
- type StreamEncryptOptions
Constants ¶
View Source
const ( // Browser-compatible cryptographic defaults. SaltLength = 16 IVLength = 12 KeyLengthBytes = 32 AuthTagLength = 16 PBKDF2Iterations = 100_000 EncryptionMarkerPassword byte = 0x01 EncryptionMarkerKeyfile byte = 0x02 EncryptionMarkerPasswordStream byte = 0x11 EncryptionMarkerKeyfileStream byte = 0x12 StreamFormatVersion byte = 0x01 DefaultChunkSize = 64 * 1024 DefaultStreamingThreshold = 100 * 1024 * 1024 // 100MB )
Variables ¶
This section is empty.
Functions ¶
func ComputeKeyFileHash ¶
func DecryptFile ¶
func DecryptFile(srcPath, dstPath string, opts DecryptOptions) error
DecryptFile auto-detects non-streaming and streaming formats.
func DecryptReader ¶
func DecryptStreamBytes ¶
func DecryptStreamBytes(data []byte, opts StreamDecryptOptions) ([]byte, error)
func EncryptAuto ¶
func EncryptAuto(data []byte, opts AutoEncryptOptions) ([]byte, error)
func EncryptFileStream ¶
func EncryptFileStream(srcPath, dstPath string, opts StreamEncryptOptions) error
EncryptFileStream writes streaming format (0x11 or 0x12) to dstPath.
func EncryptReader ¶
func EncryptStreamBytes ¶
func EncryptStreamBytes(data []byte, opts StreamEncryptOptions) ([]byte, error)
func GenerateKeyData ¶
func GenerateKeyDataWithOptions ¶
func GenerateKeyDataWithOptions(opts KeyFileOptions) (string, error)
func IsCryptoErrorCode ¶
func IsEncryptedData ¶
func IsStreamingEncryption ¶
func IsStreamingEncryption(t EncryptionType) bool
Types ¶
type AutoEncryptOptions ¶
type CryptoError ¶
func (*CryptoError) Error ¶
func (e *CryptoError) Error() string
func (*CryptoError) Unwrap ¶
func (e *CryptoError) Unwrap() error
type DecryptOptions ¶
type EncryptOptions ¶
type EncryptionType ¶
type EncryptionType string
const ( EncryptionTypePassword EncryptionType = "password" EncryptionTypeKeyfile EncryptionType = "keyfile" EncryptionTypePasswordStream EncryptionType = "password-stream" EncryptionTypeKeyfileStream EncryptionType = "keyfile-stream" EncryptionTypeUnknown EncryptionType = "unknown" )
func DetectEncryptionType ¶
func DetectEncryptionType(data []byte, profile Profile) EncryptionType
type ErrorCode ¶
type ErrorCode string
const ( ErrInvalidInput ErrorCode = "INVALID_INPUT" ErrPasswordRequired ErrorCode = "PASSWORD_REQUIRED" ErrKeyfileRequired ErrorCode = "KEYFILE_REQUIRED" ErrInvalidPassword ErrorCode = "INVALID_PASSWORD" ErrInvalidKeyfile ErrorCode = "INVALID_KEYFILE" ErrInvalidEncryptedData ErrorCode = "INVALID_ENCRYPTED_DATA" ErrEncryptionFailed ErrorCode = "ENCRYPTION_FAILED" ErrDecryptionFailed ErrorCode = "DECRYPTION_FAILED" ErrUnsupportedFormat ErrorCode = "UNSUPPORTED_FORMAT" )
type KeyFile ¶
type KeyFile struct {
Version int `json:"version"`
Algorithm string `json:"algorithm"`
Key string `json:"key"`
CreatedAt string `json:"createdAt"`
}
func GenerateKeyFile ¶
func GenerateKeyFileWithOptions ¶
func GenerateKeyFileWithOptions(opts KeyFileOptions) (KeyFile, error)
type KeyFileOptions ¶
type Profile ¶
type Profile struct {
SaltLength int
IVLength int
KeyLengthBytes int
AuthTagLength int
PBKDF2Iterations int
MarkerPassword byte
MarkerKeyfile byte
MarkerPasswordStream byte
MarkerKeyfileStream byte
StreamVersion byte
DefaultChunkSize int
}
func BrowserCompatProfile ¶
func BrowserCompatProfile() Profile
type Progress ¶
type Progress struct {
Phase ProgressPhase
Progress int
ProcessedBytes int64
TotalBytes int64
ProcessedChunk int
}
type ProgressPhase ¶
type ProgressPhase string
const ( ProgressPhaseDerivingKey ProgressPhase = "deriving_key" ProgressPhaseEncrypting ProgressPhase = "encrypting" ProgressPhaseDecrypting ProgressPhase = "decrypting" ProgressPhaseComplete ProgressPhase = "complete" )
type StreamDecryptOptions ¶
Click to show internal directories.
Click to hide internal directories.