Documentation ¶
Index ¶
- Constants
- Variables
- func AsymmetricDecrypt(data []byte, pubKey, privKey *[KeySize]byte) ([]byte, bool)
- func AsymmetricEncrypt(data []byte, pubKey, privKey *[KeySize]byte) ([]byte, error)
- func Base64(text string) string
- func ConvertInt(s string) (bin, oct, dec, hex string, err error)
- func GenerateKey(data string) *[KeySize]byte
- func GenerateKeyStdin() *[KeySize]byte
- func GenerateKeypair() (pubKey, privKey *[KeySize]byte, err error)
- func GenerateNonce() (*[NonceSize]byte, error)
- func HashDir(path string, hashFunc HashFunc) (string, error)
- func HashFile(path string, hashFunc HashFunc) (string, error)
- func MD5(text string) string
- func MD5Data(data []byte) []byte
- func PasswordPrompt(prompt string) (password string, err error)
- func RandomString(length int) (string, error)
- func ReadKeyStdin() *[KeySize]byte
- func Sha1Data(data []byte) []byte
- func Sha256(text string) []byte
- func Sha256Data(data []byte) []byte
- func Sha512Data(data []byte) []byte
- func SymmetricDecrypt(data []byte, key *[KeySize]byte) ([]byte, error)
- func SymmetricEncrypt(data []byte, key *[KeySize]byte) ([]byte, error)
- func SymmetricEncryptStatic(data string, staticNonce *[NonceSize]byte, key *[KeySize]byte) []byte
- func ToBin(n int64) string
- func ToDec(n int64) string
- func ToHex(n int64) string
- func ToOct(n int64) string
- type HashFunc
Constants ¶
const ( KeySize = 32 NonceSize = 24 )
KeySize is 256bit
Variables ¶
var ( // ErrDecrypt means something went wrong decrypting ErrDecrypt = errors.New("error decrypting") // ErrEmptyFile means the file is empty ErrEmptyFile = errors.New("file is empty") )
Functions ¶
func AsymmetricDecrypt ¶
AsymmetricDecrypt decrypts a message
func AsymmetricEncrypt ¶
AsymmetricEncrypt encrypts a message for the given pubKey
func ConvertInt ¶
ConvertInt coverts an int into bin, hex, dec and oct
func GenerateKey ¶
GenerateKey generates a Key, by calculating the SHA-256 Hash for the given string
func GenerateKeyStdin ¶
GenerateKeyStdin can be used to set the encryption key by reading it from stdin
func GenerateKeypair ¶
GenerateKeypair generates a public and a private key
func GenerateNonce ¶
GenerateNonce creates a new random nonce.
func HashDir ¶
HashDir walks a directory and hashes all files inside afterwards all hashes are concatenated and hashed again this works because the order in which filepath.Walk walks the files is always the same
func PasswordPrompt ¶
PasswordPrompt reads a password from stdin without echoing the typed characters
func RandomString ¶
RandomString generates a length bytes long random string
func ReadKeyStdin ¶
ReadKeyStdin reads the decryption key from stdin
func Sha256Data ¶
Sha256Data calculates the Sha256 for the given data
func Sha512Data ¶
Sha512Data calculates the sha512 for the given data
func SymmetricDecrypt ¶
SymmetricDecrypt extracts the nonce from the ciphertext, and attempts to decrypt with NaCl's secretbox.
func SymmetricEncrypt ¶
SymmetricEncrypt generates a random nonce and encrypts the input using NaCl's secretbox package. The nonce is prepended to the ciphertext. A sealed message will the same size as the original message + secretbox.Overhead bytes long.
func SymmetricEncryptStatic ¶
SymmetricEncryptStatic encrypts using a fixed nonce