Documentation
¶
Index ¶
- Constants
- func EncodeKeyVersion(key KeyVersion) ([]byte, error)
- type HMACKey
- type Hash
- type KeyVersion
- type SecretKey
- func (s SecretKey) Bytes() []byte
- func (s SecretKey) Decrypt(ciphertext, associatedData []byte) ([]byte, error)
- func (s SecretKey) Encrypt(plaintext, associatedData []byte) ([]byte, error)
- func (s *SecretKey) MarshalPB(v *pb.SecretKey) error
- func (s SecretKey) Overhead() int
- func (s SecretKey) Type() SecretKeyType
- func (s *SecretKey) UnmarshalPB(v *pb.SecretKey) error
- type SecretKeyType
Constants ¶
const SecretKeySize = 32
SecretKeySize is the size of a secret key in bytes.
Variables ¶
This section is empty.
Functions ¶
func EncodeKeyVersion ¶
func EncodeKeyVersion(key KeyVersion) ([]byte, error)
EncodeKeyVersion base64-encoded binary representation of a key.
It encodes the key's binary data as base64 since some KMS keystore implementations do not accept or handle binary data properly.
Types ¶
type HMACKey ¶
type HMACKey struct {
// contains filtered or unexported fields
}
HMACKey represents a secret key used for computing HMAC checksums.
func GenerateHMACKey ¶
GenerateHMACKey generates a new random HMACKey with the specified hash function.
If random is nil the standard library crypto/rand.Reader is used.
func NewHMACKey ¶
NewHMACKey creates a new HMACKey with the specified hash function and key.
The key must be 32 bytes long.
func (*HMACKey) Equal ¶
Equal reports whether mac1 and mac2 are equal without leaking any timing information.
type Hash ¶
type Hash uint
Hash identifies a cryptographic hash function.
Supported cryptographic hash functions.
type KeyVersion ¶
type KeyVersion struct {
Key SecretKey // The secret key
HMACKey HMACKey // The HMAC key
CreatedAt time.Time // The creation timestamp of the key version
CreatedBy kes.Identity // The identity of the entity that created the key version
}
KeyVersion represents a version of a secret key.
func ParseKeyVersion ¶
func ParseKeyVersion(b []byte) (KeyVersion, error)
ParseKeyVersion parses b as ParseKeyVersion.
func (*KeyVersion) HasHMACKey ¶
func (s *KeyVersion) HasHMACKey() bool
HasHMACKey reports whether the KeyVersion has an HMAC key.
Keys created in the past did not generate a HMAC key.
func (*KeyVersion) MarshalPB ¶
func (s *KeyVersion) MarshalPB(v *pb.KeyVersion) error
MarshalPB converts the KeyVersion into its protobuf representation.
func (*KeyVersion) UnmarshalPB ¶
func (s *KeyVersion) UnmarshalPB(v *pb.KeyVersion) error
UnmarshalPB initializes the KeyVersion from its protobuf representation.
type SecretKey ¶
type SecretKey struct {
// contains filtered or unexported fields
}
SecretKey represents a secret key used for encryption and decryption.
func GenerateSecretKey ¶
func GenerateSecretKey(cipher SecretKeyType, random io.Reader) (SecretKey, error)
GenerateSecretKey generates a new random SecretKey with the specified cipher.
If random is nil the standard library crypto/rand.Reader is used.
func NewSecretKey ¶
func NewSecretKey(cipher SecretKeyType, key []byte) (SecretKey, error)
NewSecretKey creates a new SecretKey with the specified cipher and key.
The key must be SecretKeySize bytes long.
func (SecretKey) Decrypt ¶
Decrypt decrypts and authenticates the ciphertext and authenticates the associatedData.
The same associatedData used during encryption must be provided.
func (SecretKey) Encrypt ¶
Encrypt encrypts and authenticates the plaintext and authenticates the associatedData.
The same associatedData must be provided when decrypting.
type SecretKeyType ¶
type SecretKeyType uint
SecretKeyType defines the type of a secret key. Secret keys with different types are not compatible since they may differ in the encryption algorithm, key length, cipher mode, etc.
const ( // AES256 represents the AES-256-GCM secret key type. AES256 SecretKeyType = iota + 1 // ChaCha20 represents the ChaCha20-Poly1305 secret key type. ChaCha20 )
Supported secret key types.
func ParseSecretKeyType ¶
func ParseSecretKeyType(s string) (SecretKeyType, error)
ParseSecretKeyType parse s as SecretKeyType string representation and returns an error if s is not a valid representation.
func (SecretKeyType) String ¶
func (s SecretKeyType) String() string
String returns the string representation of the SecretKeyType.