Documentation ¶
Index ¶
- Variables
- func CheckHash(hash CryptoString, data []byte) (bool, error)
- func HashPassword(password string, extra_strong bool) string
- func IsArgonHash(hashstr string) (bool, error)
- func VerifyPasswordHash(password string, hashPass string) (bool, error)
- type CryptoKey
- type CryptoString
- func (cs *CryptoString) AsBytes() []byte
- func (cs *CryptoString) AsString() string
- func (cs *CryptoString) IsValid() bool
- func (cs *CryptoString) MakeEmpty()
- func (cs *CryptoString) RawData() []byte
- func (cs *CryptoString) Set(str string) error
- func (cs *CryptoString) SetFromBytes(algorithm string, buffer []byte) error
- type DecryptorKey
- type EncryptionKey
- type EncryptionPair
- func (kpair EncryptionPair) Decrypt(data string) ([]byte, error)
- func (kpair EncryptionPair) Encrypt(data []byte) (string, error)
- func (kpair EncryptionPair) GetEncryptionType() string
- func (kpair EncryptionPair) GetType() string
- func (kpair *EncryptionPair) Set(pubkey CryptoString, privkey CryptoString) error
- type EncryptorKey
- type SecretKey
- type SigningPair
- func (spair SigningPair) GetEncryptionType() string
- func (spair SigningPair) GetType() string
- func (spair *SigningPair) Set(pubkey CryptoString, privkey CryptoString) error
- func (spair SigningPair) Sign(data []byte) (CryptoString, error)
- func (spair SigningPair) Verify(data []byte, signature CryptoString) (bool, error)
- type VerificationKey
Constants ¶
This section is empty.
Variables ¶
var ErrDecryptionFailure = errors.New("decryption failure")
var ErrInvalidCS = errors.New("invalid cryptostring")
var ErrUnsupportedAlgorithm = errors.New("unsupported algorithm")
var ErrVerificationFailure = errors.New("verification failure")
Functions ¶
func CheckHash ¶
func CheckHash(hash CryptoString, data []byte) (bool, error)
CheckHash generates a CryptoString hash of the supplied data
func HashPassword ¶
HashPassword turns a string into an Argon2 password hash. Set extra_strong to true if you're feeling particularly paranoid.
func IsArgonHash ¶
IsArgonHash checks to see if the string passed is an Argon2id password hash
func VerifyPasswordHash ¶
VerifyPasswordHash takes a password and the Argon2 hash to verify against, gets the parameters from the hash, applies them to the supplied password, and returns whether or not they match and if something went wrong
Types ¶
type CryptoKey ¶
CryptoKey is a baseline interface to the different kinds of keys defined in this module
type CryptoString ¶
func GetHash ¶
func GetHash(algorithm string, data []byte) (CryptoString, error)
GetHash generates a CryptoString hash of the supplied data
func NewCS ¶
func NewCS(str string) CryptoString
New is just syntactic sugar for generating a quickie CryptoString from a string
func NewCSFromBytes ¶
func NewCSFromBytes(algorithm string, buffer []byte) CryptoString
NewFromBytes creates a CryptoString object from an algorithm and buffer of data. The new instance makes a copy of the data buffer passed to it
func (*CryptoString) AsBytes ¶
func (cs *CryptoString) AsBytes() []byte
AsBytes returns the CryptoString as a byte array
func (*CryptoString) AsString ¶
func (cs *CryptoString) AsString() string
AsString returns the state of the object as a CryptoString-formatted string
func (*CryptoString) IsValid ¶
func (cs *CryptoString) IsValid() bool
IsValid checks the internal data and returns True if it is valid
func (*CryptoString) MakeEmpty ¶
func (cs *CryptoString) MakeEmpty()
MakeEmpty returns the object to an uninitialized state
func (*CryptoString) RawData ¶
func (cs *CryptoString) RawData() []byte
RawData returns the data of the object as a series of bytes. In the event of an error, nil is returned
func (*CryptoString) Set ¶
func (cs *CryptoString) Set(str string) error
Set takes a CryptoString-formatted string and sets the object to it.
func (*CryptoString) SetFromBytes ¶
func (cs *CryptoString) SetFromBytes(algorithm string, buffer []byte) error
SetFromBytes assigns an algorithm and the associated data to the object. The caller retains ownership of the underlying data passed to it.
type DecryptorKey ¶
type EncryptionKey ¶
type EncryptionKey struct { PublicHash CryptoString PublicKey CryptoString }
EncryptionKey is like EncryptionPair, but is just used for encryption and is equivalent to just the public key
func NewEncryptionKey ¶
func NewEncryptionKey(pubkey CryptoString) *EncryptionKey
NewEncryptionKey creates a new EncryptionKey object from a CryptoString of the public key
func (EncryptionKey) Encrypt ¶
func (ekey EncryptionKey) Encrypt(data []byte) (string, error)
Encrypt encrypts a byte slice using the internal public key. It returns the resulting encrypted data as a Base85-encoded string that amounts to a CryptoString without the prefix.
func (EncryptionKey) GetEncryptionType ¶
func (ekey EncryptionKey) GetEncryptionType() string
GetEncryptionType returns the algorithm used by the key
func (EncryptionKey) GetType ¶
func (ekey EncryptionKey) GetType() string
GetType returns the type of key -- asymmetric or symmetric
func (*EncryptionKey) Set ¶
func (ekey *EncryptionKey) Set(pubkey CryptoString) error
Set assigns a CryptoString to the instance
type EncryptionPair ¶
type EncryptionPair struct { PublicHash CryptoString PrivateHash CryptoString PublicKey CryptoString PrivateKey CryptoString }
EncryptionPair defines a pair of asymmetric encryption keys
func GenerateEncryptionPair ¶
func GenerateEncryptionPair() (*EncryptionPair, error)
Generate creates a new EncryptionPair instance with a brand new set of keys
func NewEncryptionPair ¶
func NewEncryptionPair(pubkey CryptoString, privkey CryptoString) *EncryptionPair
NewEncryptionPair creates a new EncryptionPair object from two CryptoString objects
func (EncryptionPair) Decrypt ¶
func (kpair EncryptionPair) Decrypt(data string) ([]byte, error)
Decrypt decrypts a string of encrypted data which is Base85 encoded using the internal private key.
func (EncryptionPair) Encrypt ¶
func (kpair EncryptionPair) Encrypt(data []byte) (string, error)
Encrypt encrypts a byte slice using the internal public key. It returns the resulting encrypted data as a Base85-encoded string that amounts to a CryptoString without the prefix.
func (EncryptionPair) GetEncryptionType ¶
func (kpair EncryptionPair) GetEncryptionType() string
GetEncryptionType returns the algorithm used by the key
func (EncryptionPair) GetType ¶
func (kpair EncryptionPair) GetType() string
GetType returns the type of key -- asymmetric or symmetric
func (*EncryptionPair) Set ¶
func (kpair *EncryptionPair) Set(pubkey CryptoString, privkey CryptoString) error
Set assigns a pair of CryptoString values to the EncryptionPair
type EncryptorKey ¶
type SecretKey ¶
type SecretKey struct { Hash CryptoString Key CryptoString }
SecretKey defines a symmetric encryption key
func GenerateSecretKey ¶
func GenerateSecretKey() *SecretKey
GenerateSecretKey creates a new SecretKey object with a randomly-generated key using a cryptographically safe method
func NewSecretKey ¶
func NewSecretKey(keyString CryptoString) *SecretKey
NewSecretKey creates a new NewSecretKey object from a CryptoString of the key
func (SecretKey) Decrypt ¶
Decrypt decrypts a string of encrypted data which is Base85 encoded using the internal key.
func (SecretKey) Encrypt ¶
Encrypt encrypts a byte slice using the internal key. It returns the resulting encrypted data as a Base85-encoded string that amounts to a CryptoString without the prefix.
func (SecretKey) GetEncryptionType ¶
GetEncryptionType returns the algorithm used by the key
func (*SecretKey) Set ¶
func (key *SecretKey) Set(keyString CryptoString) error
Set assigns a CryptoString value to the SecretKey
type SigningPair ¶
type SigningPair struct { PublicHash CryptoString PrivateHash CryptoString PublicKey CryptoString PrivateKey CryptoString }
SigningPair defines an asymmetric signing key pair
func GenerateSigningPair ¶
func GenerateSigningPair() (*SigningPair, error)
GenerateSigningPair creates a new instance with a randomly-generated key pair
func NewSigningPair ¶
func NewSigningPair(pubkey CryptoString, privkey CryptoString) *SigningPair
NewSigningPair creates a new SigningPair object from two CryptoString objects
func (SigningPair) GetEncryptionType ¶
func (spair SigningPair) GetEncryptionType() string
GetEncryptionType returns the algorithm used by the key
func (SigningPair) GetType ¶
func (spair SigningPair) GetType() string
GetType returns the type of key -- asymmetric or symmetric
func (*SigningPair) Set ¶
func (spair *SigningPair) Set(pubkey CryptoString, privkey CryptoString) error
Set assigns a pair of CryptoString values to the SigningPair
func (SigningPair) Sign ¶
func (spair SigningPair) Sign(data []byte) (CryptoString, error)
Sign cryptographically signs a byte slice.
func (SigningPair) Verify ¶
func (spair SigningPair) Verify(data []byte, signature CryptoString) (bool, error)
Verify uses the internal verification key with the passed data and signature and returns true if the signature has verified the data with that key.
type VerificationKey ¶
type VerificationKey struct { PublicHash CryptoString // contains filtered or unexported fields }
VerificationKey is an object to represent just a verification key, not a key pair
func NewVerificationKey ¶
func NewVerificationKey(key CryptoString) *VerificationKey
NewVerificationKey creates a new verification key from a CryptoString
func (VerificationKey) GetEncryptionType ¶
func (vkey VerificationKey) GetEncryptionType() string
GetEncryptionType returns the algorithm used by the key
func (VerificationKey) GetType ¶
func (vkey VerificationKey) GetType() string
GetType returns the type of key -- asymmetric or symmetric
func (*VerificationKey) Set ¶
func (vkey *VerificationKey) Set(key CryptoString) error
Set assigns a CryptoString value to the key
func (VerificationKey) Verify ¶
func (vkey VerificationKey) Verify(data []byte, signature CryptoString) (bool, error)
Verify uses the internal verification key with the passed data and signature and returns true if the signature has verified the data with that key.