Documentation ¶
Overview ¶
Package goenc contains functions for working with encryption
Index ¶
- Constants
- func DeriveKey(pass, salt []byte, N, keySize int) ([]byte, error)
- func EncryptAndSave(cipher BlockCipher, key, plaintext []byte, path string) error
- func EncryptAndSaveWithPerms(cipher BlockCipher, key, plaintext []byte, path string, perm os.FileMode) error
- func ReadEncryptedFile(cipher BlockCipher, key []byte, path string) ([]byte, error)
- func Zero(data []byte)
- type BlockCipher
- type Cipher
- type CipherKind
- type Message
- type MockBlockCipher
Constants ¶
const ( // InteractiveComplexity - recommended complexity for interactive sessions InteractiveComplexity = 1 << (iota + 14) // Complexity15 is 2^15 Complexity15 // Complexity16 is 2^16 Complexity16 // Complexity17 is 2^17 Complexity17 // Complexity18 is 2^18 Complexity18 // Complexity19 is 2^19 Complexity19 // AggressiveComplexity is 2^20 (don't use this unless you have incredibly strong CPU power AggressiveComplexity )
Overhead is the amount of Overhead contained in the ciphertext
const (
// SaltSize sets a generic salt size
SaltSize = 64
)
Variables ¶
This section is empty.
Functions ¶
func DeriveKey ¶
DeriveKey generates a new NaCl key from a passphrase and salt. This is a costly operation.
func EncryptAndSave ¶
func EncryptAndSave(cipher BlockCipher, key, plaintext []byte, path string) error
EncryptAndSave encrypts data and saves it to a file with the permissions 0644
func EncryptAndSaveWithPerms ¶
func EncryptAndSaveWithPerms(cipher BlockCipher, key, plaintext []byte, path string, perm os.FileMode) error
EncryptAndSaveWithPerms encrypts data and saves it to a file with the given permissions using the given key
func ReadEncryptedFile ¶
func ReadEncryptedFile(cipher BlockCipher, key []byte, path string) ([]byte, error)
ReadEncryptedFile reads a file a path and attempts to decrypt the data there with the given key
Types ¶
type BlockCipher ¶
type BlockCipher interface { Encrypt(key, plaintext []byte) ([]byte, error) Decrypt(key, ciphertext []byte) ([]byte, error) KeySize() int }
BlockCipher represents a cipher that encodes and decodes chunks of data at a time
type Cipher ¶
type Cipher struct { BlockCipher DerivedKeyN int }
Cipher is a struct that contains a BlockCipher interface and stores a DerivedKey Complexity number
func NewCipher ¶
func NewCipher(kind CipherKind, derivedKeyN int, args ...[]byte) (*Cipher, error)
NewCipher returns a new Cipher containing a BlockCipher interface based on the CipherKind
func (*Cipher) DecryptWithPassword ¶
Decrypt takes a password and ciphertext, derives a key, and attempts to decrypt that data
func (*Cipher) EncryptWithPassword ¶
EncryptWithPassword takes a password, plaintext, and derives a key based on that password, then encrypting that data with the underlying block cipher and appending the salt to the output
type CipherKind ¶
type CipherKind int
CipherKind represents what kind of cipher to use
const ( CBC CipherKind = iota CFB CTR GCM NaCL Mock )
CipherKind constants
type Message ¶
Message represents a message being passed, and contains its contents and a sequence number
func UnmarshalMessage ¶
UnmarshalMessage decodes bytes into a message pointer
type MockBlockCipher ¶
type MockBlockCipher struct{}
MockBlockCipher implements BlockCipher but does nothing
func (*MockBlockCipher) Decrypt ¶
func (m *MockBlockCipher) Decrypt(key, ciphertext []byte) ([]byte, error)
Decrypt in this case is only implementing the BlockCipher interface, it doesn't do anything
func (*MockBlockCipher) Encrypt ¶
func (m *MockBlockCipher) Encrypt(key, plaintext []byte) ([]byte, error)
Encrypt in this case is only implementing the BlockCipher interface, it doesn't do anything
func (*MockBlockCipher) KeySize ¶
func (m *MockBlockCipher) KeySize() int
KeySize is a mock key size to use with the mock cipher
Directories ¶
Path | Synopsis |
---|---|
aes
|
|
cbc
Package cbc supports cbc encryption - this implementation is authenticated with crypto/hmac using sha256
|
Package cbc supports cbc encryption - this implementation is authenticated with crypto/hmac using sha256 |
cfb
Package cfb supports basic cfb encryption with NO HMAC
|
Package cfb supports basic cfb encryption with NO HMAC |
ctr
Package ctr supports ctr encryption - this implementation is authenticated with crypto/hmac using sha256
|
Package ctr supports ctr encryption - this implementation is authenticated with crypto/hmac using sha256 |
gcm
Package gcm supports gcm encryption - gcm is authenticated by default
|
Package gcm supports gcm encryption - gcm is authenticated by default |
Package nacl provides encryption by salting a key with a pad
|
Package nacl provides encryption by salting a key with a pad |
Package ssh supports generation of key pairs in different formats with as few parameters as possible
|
Package ssh supports generation of key pairs in different formats with as few parameters as possible |