Documentation
¶
Index ¶
- Variables
- func CertifiedAlgorithmsRequired() bool
- func CheckHash(hash CryptoString, data []byte) (bool, error)
- func GetAsymmetricAlgorithms() []string
- func GetHashAlgorithms() []string
- func GetSecretAlgorithms() []string
- func GetSigningAlgorithms() []string
- func HashPassword(password string) string
- func IsArgonHash(hashstr string) (bool, error)
- func IsCertifiedAlgorithm(algorithm string) bool
- func PreferredAsymmetricType() string
- func PreferredHashType() string
- func PreferredSecretType() string
- func PreferredSigningType() string
- func RequireCertifiedAlgorithms(require bool)
- 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 CertifiedAlgorithmsRequired ¶ added in v0.2.0
func CertifiedAlgorithmsRequired() bool
Returns true if the library is using only certified algorithms
func CheckHash ¶
func CheckHash(hash CryptoString, data []byte) (bool, error)
CheckHash generates a CryptoString hash of the supplied data
func GetAsymmetricAlgorithms ¶ added in v0.2.0
func GetAsymmetricAlgorithms() []string
Returns a list of supported asymmetric encryption algorithms
func GetHashAlgorithms ¶ added in v0.2.0
func GetHashAlgorithms() []string
Returns a list of supported hash algorithms
func GetSecretAlgorithms ¶ added in v0.2.0
func GetSecretAlgorithms() []string
Returns a list of supported symmetric encryption algorithms
func GetSigningAlgorithms ¶ added in v0.2.0
func GetSigningAlgorithms() []string
Returns a list of supported signing algorithms
func HashPassword ¶
HashPassword turns a string into an Argon2 password hash.
func IsArgonHash ¶
IsArgonHash checks to see if the string passed is an Argon2id password hash
func IsCertifiedAlgorithm ¶ added in v0.2.0
Returns true if the requested algorithm is one of the certified algorithms supported by the library. For those curious, this is as follows:
RSA2048-SHA256: 2048-bit RSA with SHA256 for internal hashing. PKCS #1, RFC 8017, and an allowed (but not approved) algorithm for key transport in FIPS 140-2.
ECDSA: Digital signatures using elliptic curve P-256 and SHA256 for internal hashing. FIPS 186-4 and SEC 1, Version 2.0
AES-128, AES-256: FIPS Publication 197.
SHA-256, SHA-512: 256-bit and 512-bit variants of the SHA2 hashing algorithm as documented in FIPS 180-4.
SHAKE-256, SHAKE-512: The SHAKE128 and SHAKE256 hashing algorithms, published in FIPS publication 202. Note that these algorithms require a 2x hash length to provide the corresponding 128 bits and 256 bits of security. The goeznacl prefixes denote the bit length of the hash, not the bits of security granted.
The ED25519 signature algorithm is an approved digital signature algorithm in the current draft of FIPS 186-5, but because the draft has not received final approval, it is not in this list.
As far as I am aware, there is no mention of Curve25519 asymmetric encryption as being allowed for key transport, but it is possible that it will achieve this status at some point in the future.
func PreferredAsymmetricType ¶ added in v0.2.0
func PreferredAsymmetricType() string
Returns the name of the library's recommended asymmetric encryption algorithm
func PreferredHashType ¶ added in v0.2.0
func PreferredHashType() string
Returns the name of the library's recommended hash algorithm
func PreferredSecretType ¶ added in v0.2.0
func PreferredSecretType() string
Returns the name of the library's recommended secret key algorithm
func PreferredSigningType ¶ added in v0.2.0
func PreferredSigningType() string
Returns the name of the library's recommended signing algorithm
func RequireCertifiedAlgorithms ¶ added in v0.2.0
func RequireCertifiedAlgorithms(require bool)
Tells the library to require (or not) certified algorithms, which defaults to not requiring them. Unless you have specific requirements to use this, don't. The recommended choices provide a balance of ease of use, speed, key size, and interoperability.
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
NewCS generates an instance from a string containing CryptoString data
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 and Base85-encodes it for you. If you have an existing key or hash, this is probably what you want to use.
func (*CryptoString) AsBytes ¶
func (cs *CryptoString) AsBytes() []byte
AsBytes returns the instance's prefix and encoded data as a byte slice
func (*CryptoString) AsString ¶
func (cs *CryptoString) AsString() string
AsString returns the instance's prefix and encoded data as a 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 raw, unencoded data of the object as a byte slice. 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(algorithm string) (*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 ¶
GenerateSecretKey creates a new SecretKey object with a randomly-generated key using a cryptographically safe method. This will return nil if given an invalid encryption algorithm
func NewSecretKey ¶
func NewSecretKey(keyString CryptoString) *SecretKey
NewSecretKey creates a new NewSecretKey object from a CryptoString of the key. If given a bad key or one which uses an unsupported algorithm, it will return nil.
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(algorithm string) (*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.