Documentation
¶
Index ¶
- func GenerateEd25519KeyFiles(dir string, filename string) (string, error)
- func NewDecryptedString(encryptedValue string) string
- type Bcrypt
- type EncryptedString
- func (v EncryptedString) MarshalBinary() ([]byte, error)
- func (v EncryptedString) MarshalText() ([]byte, error)
- func (v EncryptedString) String() string
- func (v *EncryptedString) UnmarshalBinary(text []byte) error
- func (v *EncryptedString) UnmarshalText(text []byte) error
- func (v EncryptedString) Value() string
- type SymCrypt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateEd25519KeyFiles ¶
GenerateEd25519KeyFiles generates two files id_ed25519 and id_ed25519.pub in directory dir. Source: https://github.com/mikesmitty/edkey/blob/master/edkey.go. It returns the fully qualified path to the public key file.
func NewDecryptedString ¶
NewDecryptedString decrypts an encrypted string
Types ¶
type Bcrypt ¶
type Bcrypt interface {
// Encrypt takes plainText and encrypts it with bcrypt and its costs (default = 4).
// It returns the encrypted string or an empty string on error.
Encrypt(plainText string) (string, error)
// Cost sets bcrypt costs (and checks its bounds)
Cost(cost int)
// HashedText allows to set a hased text string like e.g. $2a$04$vH2ABneGM7Lpl0oGkvAgtOCIF29Ku.TUPx5.CLD1.EKLl2RgT6ilK
HashedText(hashedText string)
// PlainText allows to set a plain text string
PlainText(plainText string)
// Compare checks the hash against the plaintext (hashed) and returns true
// on success
Compare() bool
}
Bcrypt is the main interface
type EncryptedString ¶
type EncryptedString struct {
// contains filtered or unexported fields
}
EncryptedString is a sym crypt string. It automatically gets encrypted when created. It also implements the Marshall/Unmarshall Text/Binary go interfaces for easier usage.
func NewEncryptedString ¶
func NewEncryptedString(plainTextValue string) EncryptedString
NewEncryptedString creates a new EncryptedString by encrypting the supplied plainTextValue.
func (EncryptedString) MarshalBinary ¶
func (v EncryptedString) MarshalBinary() ([]byte, error)
func (EncryptedString) MarshalText ¶
func (v EncryptedString) MarshalText() ([]byte, error)
func (EncryptedString) String ¶
func (v EncryptedString) String() string
Value returns the decrypted plainTextValue.
func (*EncryptedString) UnmarshalBinary ¶
func (v *EncryptedString) UnmarshalBinary(text []byte) error
func (*EncryptedString) UnmarshalText ¶
func (v *EncryptedString) UnmarshalText(text []byte) error
func (EncryptedString) Value ¶
func (v EncryptedString) Value() string
Value returns the decrypted plainTextValue.
type SymCrypt ¶
type SymCrypt struct {
// contains filtered or unexported fields
}
SymCrypt is the main structure for symmetric encryption and holds plainText, key and cipher as unexported fields.
Usage sample:
// cipher e.g. "gQTf9p9trkvx3xvSKAQhLIfqUWirxnf5Sl+YzAKV5zjS0hLZ0LRXs+1rb6M="
cipher := crypt.NewSymmetricEncryption().SetPlainText("mySecretPassword").GetCypherBase64()
plain := crypt.NewSymmetricEncryption().SetCypherBase64(cipher).GetPlainText()
if plain != "mySecretPassword" {
log.Println("ERROR: expected 'mySecretPassword'")
}
func NewSymmetricEncryption ¶
func NewSymmetricEncryption() *SymCrypt
NewSymmetricEncryption is the entry point for AES encryption/decryption and can be used to encrypt a string and get the result as base64 string. When the key is not configured it uses a built in one (should not be used in production environment).
func (*SymCrypt) GetCypherBase64 ¶
GetCypherBase64 returns the encrypted data stream as base64 encoded string like e.g. 8q+orlJS5rzn0HtzbmFIkJIGAoOIL3zczlXVTUylRU021g==. It returns an empty string on error
func (*SymCrypt) GetPlainText ¶
GetPlainText returns the plaintext
func (*SymCrypt) SetCypherBase64 ¶
SetCypherBase64 adds s.cipher - but as base64 string.
func (*SymCrypt) SetKey ¶
SetKey adds an AES key - the length is not so important because it is stripped or expanded to exactly 32 chars (256 bit).
func (*SymCrypt) SetPlainText ¶
SetPlainText text adds the text we want to encrypt.