Documentation
¶
Index ¶
- Constants
- Variables
- func Base64Decode(data []byte) ([]byte, error)
- func Base64Encode(data []byte) []byte
- func CalculateHKDF(salt []byte, secret []byte) ([]byte, error)
- func CalculateSHA256(data []byte) []byte
- func CalculateSHA256Hmac(secret, data []byte) []byte
- func CompressedECPublicKey(mode ECCMode, pubKey ecdsa.PublicKey) ([]byte, error)
- func ComputeECDHKey(privateKeyInPem []byte, publicKeyInPem []byte) ([]byte, error)
- func ComputeECDHKeyFromEC(publicKey *ecdsa.PublicKey, privateKey *ecdsa.PrivateKey) ([]byte, error)
- func ComputeECDHKeyFromECDHKeys(publicKey *ecdh.PublicKey, privateKey *ecdh.PrivateKey) ([]byte, error)
- func ComputeECDSASig(digest []byte, privKey *ecdsa.PrivateKey) ([]byte, []byte, error)
- func ConvertToECDHPrivateKey(key interface{}) (*ecdh.PrivateKey, error)
- func ConvertToECDHPublicKey(key interface{}) (*ecdh.PublicKey, error)
- func ECPrivateKeyFromPem(privateECKeyInPem []byte) (*ecdh.PrivateKey, error)
- func ECPrivateKeyInPemFormat(privateKey ecdsa.PrivateKey) (string, error)
- func ECPubKeyFromPem(pemECPubKey []byte) (*ecdh.PublicKey, error)
- func ECPublicKeyInPemFormat(publicKey ecdsa.PublicKey) (string, error)
- func GetECCurveFromECCMode(mode ECCMode) (elliptic.Curve, error)
- func GetECKeySize(pemData []byte) (int, error)
- func HybridWrapDEK(ktype KeyType, kasPublicKeyPEM string, dek []byte) ([]byte, error)
- func IsECKeyType(kt KeyType) bool
- func IsHybridKeyType(kt KeyType) bool
- func IsPEMOrDERPrivateKey(data []byte) bool
- func IsRSAKeyType(kt KeyType) bool
- func P256MLKEM768Encapsulate(publicKeyRaw []byte) ([]byte, []byte, error)
- func P256MLKEM768PrivateKeyFromPem(data []byte) ([]byte, error)
- func P256MLKEM768PubKeyFromPem(data []byte) ([]byte, error)
- func P256MLKEM768UnwrapDEK(privateKeyRaw, wrappedDER []byte) ([]byte, error)
- func P256MLKEM768WrapDEK(publicKeyRaw, dek []byte) ([]byte, error)
- func P384MLKEM1024Encapsulate(publicKeyRaw []byte) ([]byte, []byte, error)
- func P384MLKEM1024PrivateKeyFromPem(data []byte) ([]byte, error)
- func P384MLKEM1024PubKeyFromPem(data []byte) ([]byte, error)
- func P384MLKEM1024UnwrapDEK(privateKeyRaw, wrappedDER []byte) ([]byte, error)
- func P384MLKEM1024WrapDEK(publicKeyRaw, dek []byte) ([]byte, error)
- func RSAKeyTypeToBits(kt KeyType) (int, error)
- func RandomBytes(size int) ([]byte, error)
- func SHA256AsHex(data []byte) []byte
- func SHA256HmacAsHex(secret, data []byte) []byte
- func UncompressECPubKey(curve elliptic.Curve, compressedPubKey []byte) (*ecdsa.PublicKey, error)
- func VerifyECDSASig(digest, r, s []byte, pubKey *ecdsa.PublicKey) bool
- func XWingEncapsulate(publicKeyRaw []byte) ([]byte, []byte, error)
- func XWingPrivateKeyFromPem(data []byte) ([]byte, error)
- func XWingPubKeyFromPem(data []byte) ([]byte, error)
- func XWingUnwrapDEK(privateKeyRaw, wrappedDER []byte) ([]byte, error)
- func XWingWrapDEK(publicKeyRaw, dek []byte) ([]byte, error)
- type AESProtectedKey
- type AesGcm
- type AsymDecryption
- type AsymEncryption
- func (e AsymEncryption) Encrypt(data []byte) ([]byte, error)
- func (e AsymEncryption) EphemeralKey() []byte
- func (e AsymEncryption) KeyType() KeyType
- func (e AsymEncryption) Metadata() (map[string]string, error)
- func (e AsymEncryption) PublicKeyInPemFormat() (string, error)
- func (e AsymEncryption) Type() SchemeType
- type ECCMode
- type ECDecryptor
- type ECEncryptor
- type ECKeyPair
- type Encapsulator
- type HybridNISTDecryptor
- func NewP256MLKEM768Decryptor(privateKey []byte) (*HybridNISTDecryptor, error)
- func NewP384MLKEM1024Decryptor(privateKey []byte) (*HybridNISTDecryptor, error)
- func NewSaltedP256MLKEM768Decryptor(privateKey, salt, info []byte) (*HybridNISTDecryptor, error)
- func NewSaltedP384MLKEM1024Decryptor(privateKey, salt, info []byte) (*HybridNISTDecryptor, error)
- type HybridNISTEncryptor
- func (e *HybridNISTEncryptor) Encrypt(data []byte) ([]byte, error)
- func (e *HybridNISTEncryptor) EphemeralKey() []byte
- func (e *HybridNISTEncryptor) KeyType() KeyType
- func (e *HybridNISTEncryptor) Metadata() (map[string]string, error)
- func (e *HybridNISTEncryptor) PublicKeyInPemFormat() (string, error)
- func (e *HybridNISTEncryptor) Type() SchemeType
- type HybridNISTKeyPair
- type HybridNISTWrappedKey
- type KeyPair
- type KeyType
- type PrivateKeyDecryptor
- type ProtectedKey
- type PublicKeyEncryptor
- type RsaKeyPair
- type SchemeType
- type XWingDecryptor
- type XWingEncryptor
- func (e *XWingEncryptor) Encrypt(data []byte) ([]byte, error)
- func (e *XWingEncryptor) EphemeralKey() []byte
- func (e *XWingEncryptor) KeyType() KeyType
- func (e *XWingEncryptor) Metadata() (map[string]string, error)
- func (e *XWingEncryptor) PublicKeyInPemFormat() (string, error)
- func (e *XWingEncryptor) Type() SchemeType
- type XWingKeyPair
- type XWingWrappedKey
Constants ¶
const ( ECCurveP256Size = 256 ECCurveP384Size = 384 ECCurveP521Size = 521 RSA2048Size = 2048 RSA4096Size = 4096 )
const ( P256MLKEM768ECPublicKeySize = 65 // uncompressed P-256 point P256MLKEM768ECPrivateKeySize = 32 // P-256 scalar P256MLKEM768MLKEMPubKeySize = 1184 // mlkem768 encapsulation key P256MLKEM768MLKEMPrivKeySize = mlkemSeedSize P256MLKEM768MLKEMCtSize = 1088 // mlkem768 ciphertext P256MLKEM768PublicKeySize = P256MLKEM768ECPublicKeySize + P256MLKEM768MLKEMPubKeySize // 1249 P256MLKEM768PrivateKeySize = P256MLKEM768ECPrivateKeySize + P256MLKEM768MLKEMPrivKeySize // 96 P256MLKEM768CiphertextSize = P256MLKEM768ECPublicKeySize + P256MLKEM768MLKEMCtSize // 1153 PEMBlockP256MLKEM768PublicKey = "SECP256R1 MLKEM768 PUBLIC KEY" PEMBlockP256MLKEM768PrivateKey = "SECP256R1 MLKEM768 PRIVATE KEY" )
Sizes for P-256 + ML-KEM-768 hybrid.
const ( P384MLKEM1024ECPublicKeySize = 97 // uncompressed P-384 point P384MLKEM1024ECPrivateKeySize = 48 // P-384 scalar P384MLKEM1024MLKEMPubKeySize = 1568 // mlkem1024 encapsulation key P384MLKEM1024MLKEMPrivKeySize = mlkemSeedSize P384MLKEM1024MLKEMCtSize = 1568 // mlkem1024 ciphertext P384MLKEM1024PublicKeySize = P384MLKEM1024ECPublicKeySize + P384MLKEM1024MLKEMPubKeySize // 1665 P384MLKEM1024PrivateKeySize = P384MLKEM1024ECPrivateKeySize + P384MLKEM1024MLKEMPrivKeySize // 112 P384MLKEM1024CiphertextSize = P384MLKEM1024ECPublicKeySize + P384MLKEM1024MLKEMCtSize // 1665 PEMBlockP384MLKEM1024PublicKey = "SECP384R1 MLKEM1024 PUBLIC KEY" PEMBlockP384MLKEM1024PrivateKey = "SECP384R1 MLKEM1024 PRIVATE KEY" )
Sizes for P-384 + ML-KEM-1024 hybrid.
const ( HybridXWingKey KeyType = "hpqt:xwing" XWingPublicKeySize = xwing.PublicKeySize XWingPrivateKeySize = xwing.PrivateKeySize XWingCiphertextSize = xwing.CiphertextSize PEMBlockXWingPublicKey = "XWING PUBLIC KEY" PEMBlockXWingPrivateKey = "XWING PRIVATE KEY" )
const DefaultNonceSize = 16
DefaultNonceSize The default nonce size for the TDF3 encryption.
const GcmStandardNonceSize = 12
Variables ¶
var ( // ErrEmptyKeyData is returned when the key data is empty ErrEmptyKeyData = errors.New("key data is empty") // ErrPolicyHMACMismatch is returned when policy binding verification fails ErrPolicyHMACMismatch = errors.New("policy HMAC mismatch") )
var ErrInvalidCiphertext = errors.New("invalid ciphertext")
ErrInvalidCiphertext is returned when ciphertext or input data is invalid (empty, wrong size, etc.)
var ErrInvalidKeyData = errors.New("invalid key data")
ErrInvalidKeyData is returned when key data is invalid (empty, nil, or wrong size)
var ErrUnsupportedAESGCMConfiguration = errors.New("unsupported AES-GCM configuration")
ErrUnsupportedAESGCMConfiguration is returned for AES-GCM options that Go strict FIPS mode does not allow.
Functions ¶
func Base64Decode ¶
Base64Decode Decode the data using base64 decoding.
func Base64Encode ¶
Base64Encode Encode the data to base64 encoding. Note: bas64 encoding causing ~33% overhead.
func CalculateHKDF ¶ added in v0.1.1
CalculateHKDF generate a key using key derivation function.
func CalculateSHA256 ¶
CalculateSHA256 Calculate the SHA256 checksum of the data(32 bytes).
func CalculateSHA256Hmac ¶
CalculateSHA256Hmac Calculate the hmac of the data with given secret.
func CompressedECPublicKey ¶ added in v0.1.4
CompressedECPublicKey - return a compressed key from the supplied curve and public key
func ComputeECDHKey ¶ added in v0.1.1
ComputeECDHKey calculate shared secret from public key from one party and the private key from another party.
func ComputeECDHKeyFromEC ¶ added in v0.1.4
func ComputeECDHKeyFromECDHKeys ¶ added in v0.1.4
func ComputeECDSASig ¶ added in v0.1.4
ComputeECDSASig compute ecdsa signature
func ConvertToECDHPrivateKey ¶ added in v0.1.1
func ConvertToECDHPrivateKey(key interface{}) (*ecdh.PrivateKey, error)
ConvertToECDHPrivateKey convert the ec private key to ECDH private key
func ConvertToECDHPublicKey ¶ added in v0.1.1
ConvertToECDHPublicKey convert the ec public key to ECDH public key
func ECPrivateKeyFromPem ¶ added in v0.1.1
func ECPrivateKeyFromPem(privateECKeyInPem []byte) (*ecdh.PrivateKey, error)
ECPrivateKeyFromPem generate ec private from pem format
func ECPrivateKeyInPemFormat ¶ added in v0.1.4
func ECPrivateKeyInPemFormat(privateKey ecdsa.PrivateKey) (string, error)
ECPrivateKeyInPemFormat Returns private key in pem format.
func ECPubKeyFromPem ¶ added in v0.1.1
ECPubKeyFromPem generate ec public from pem format
func ECPublicKeyInPemFormat ¶ added in v0.1.4
ECPublicKeyInPemFormat Returns public key in pem format.
func GetECCurveFromECCMode ¶ added in v0.1.5
GetECCurveFromECCMode return elliptic curve from ecc mode
func GetECKeySize ¶ added in v0.1.8
GetECKeySize returns the curve size from a PEM-encoded EC public key
func HybridWrapDEK ¶ added in v0.11.0
HybridWrapDEK parses the recipient's hybrid public key PEM, encapsulates against it using the scheme implied by ktype, and returns the ASN.1-encoded wrapped DEK envelope used in `hybrid-wrapped` manifests. It dispatches across both the X-Wing and NIST EC + ML-KEM families so SDK call sites do not need to repeat the algorithm switch.
The HKDF salt is the default TDF salt; callers that need a non-default salt should call the per-scheme `*WrapDEK` helpers directly.
func IsECKeyType ¶ added in v0.1.8
func IsHybridKeyType ¶ added in v0.11.0
IsHybridKeyType returns true if the key type is a hybrid post-quantum type.
func IsPEMOrDERPrivateKey ¶ added in v0.10.0
IsPEMOrDERPrivateKey reports whether data appears to be an unencrypted private key in PEM or DER format. It does not attempt decryption or key unwrapping.
func IsRSAKeyType ¶ added in v0.1.8
func P256MLKEM768Encapsulate ¶ added in v0.11.0
P256MLKEM768Encapsulate performs P-256 ECDH + ML-KEM-768 hybrid encapsulation.
func P256MLKEM768PrivateKeyFromPem ¶ added in v0.11.0
func P256MLKEM768PubKeyFromPem ¶ added in v0.11.0
func P256MLKEM768UnwrapDEK ¶ added in v0.11.0
func P256MLKEM768WrapDEK ¶ added in v0.11.0
func P384MLKEM1024Encapsulate ¶ added in v0.11.0
P384MLKEM1024Encapsulate performs P-384 ECDH + ML-KEM-1024 hybrid encapsulation.
func P384MLKEM1024PrivateKeyFromPem ¶ added in v0.11.0
func P384MLKEM1024PubKeyFromPem ¶ added in v0.11.0
func P384MLKEM1024UnwrapDEK ¶ added in v0.11.0
func P384MLKEM1024WrapDEK ¶ added in v0.11.0
func RSAKeyTypeToBits ¶ added in v0.1.8
func RandomBytes ¶
RandomBytes Generates random bytes of given size.
func SHA256AsHex ¶
SHA256AsHex Calculate the SHA256 checksum of the data and return in hex format(64 bytes).
func SHA256HmacAsHex ¶
SHA256HmacAsHex Calculate the hmac of the data with given secret and return in hex format.
func UncompressECPubKey ¶ added in v0.1.5
UncompressECPubKey create EC public key from compressed form
func VerifyECDSASig ¶ added in v0.1.5
VerifyECDSASig verify ecdsa signature.
func XWingEncapsulate ¶ added in v0.11.0
XWingEncapsulate performs the X-Wing KEM encapsulation, returning the shared secret and ciphertext without applying KDF or encryption.
func XWingPrivateKeyFromPem ¶ added in v0.11.0
func XWingPubKeyFromPem ¶ added in v0.11.0
func XWingUnwrapDEK ¶ added in v0.11.0
func XWingWrapDEK ¶ added in v0.11.0
Types ¶
type AESProtectedKey ¶ added in v0.4.0
type AESProtectedKey struct {
// contains filtered or unexported fields
}
AESProtectedKey implements the ProtectedKey interface with an in-memory secret key
func NewAESProtectedKey ¶ added in v0.4.0
func NewAESProtectedKey(rawKey []byte) (*AESProtectedKey, error)
NewAESProtectedKey creates a new instance of AESProtectedKey
func (*AESProtectedKey) DecryptAESGCM ¶ added in v0.4.0
DecryptAESGCM decrypts data using AES-GCM with the protected key
func (*AESProtectedKey) Export
deprecated
added in
v0.4.0
func (k *AESProtectedKey) Export(encapsulator Encapsulator) ([]byte, error)
Export returns the raw key data, optionally encrypting it with the provided Encapsulator
Deprecated: Use the Encapsulator's Encapsulate method instead.
func (*AESProtectedKey) VerifyBinding ¶ added in v0.4.0
func (k *AESProtectedKey) VerifyBinding(_ context.Context, policy, policyBinding []byte) error
VerifyBinding checks if the policy binding matches the given policy data
type AesGcm ¶
type AesGcm struct {
// contains filtered or unexported fields
}
func (AesGcm) Decrypt ¶
Decrypt decrypts data with a 12-byte nonce prefix and a 16-byte AES-GCM authentication tag.
type AsymDecryption ¶
type AsymDecryption struct {
PrivateKey *rsa.PrivateKey
}
func NewAsymDecryption ¶
func NewAsymDecryption(privateKeyInPem string) (AsymDecryption, error)
type AsymEncryption ¶
func NewAsymEncryption
deprecated
func NewAsymEncryption(publicKeyInPem string) (AsymEncryption, error)
NewAsymEncryption creates and returns a new AsymEncryption.
Deprecated: Use FromPublicPEM instead.
func (AsymEncryption) EphemeralKey ¶ added in v0.1.8
func (e AsymEncryption) EphemeralKey() []byte
func (AsymEncryption) KeyType ¶ added in v0.7.0
func (e AsymEncryption) KeyType() KeyType
func (AsymEncryption) Metadata ¶ added in v0.1.8
func (e AsymEncryption) Metadata() (map[string]string, error)
func (AsymEncryption) PublicKeyInPemFormat ¶
func (e AsymEncryption) PublicKeyInPemFormat() (string, error)
func (AsymEncryption) Type ¶ added in v0.1.8
func (e AsymEncryption) Type() SchemeType
type ECCMode ¶
type ECCMode uint8
func ECKeyTypeToMode ¶ added in v0.1.8
func ECSizeToMode ¶ added in v0.1.8
ECSizeToMode converts a curve size to an ECCMode
type ECDecryptor ¶ added in v0.1.8
type ECDecryptor struct {
// contains filtered or unexported fields
}
func NewECDecryptor ¶ added in v0.1.8
func NewECDecryptor(sk *ecdh.PrivateKey) (ECDecryptor, error)
func NewSaltedECDecryptor ¶ added in v0.2.0
func NewSaltedECDecryptor(sk *ecdh.PrivateKey, salt, info []byte) (ECDecryptor, error)
func (ECDecryptor) DecryptWithEphemeralKey ¶ added in v0.1.8
func (e ECDecryptor) DecryptWithEphemeralKey(data, ephemeral []byte) ([]byte, error)
type ECEncryptor ¶ added in v0.1.8
type ECEncryptor struct {
// contains filtered or unexported fields
}
func (ECEncryptor) Encrypt ¶ added in v0.1.8
func (e ECEncryptor) Encrypt(data []byte) ([]byte, error)
Encrypts the data with the EC public key.
func (ECEncryptor) EphemeralKey ¶ added in v0.1.8
func (e ECEncryptor) EphemeralKey() []byte
func (ECEncryptor) KeyType ¶ added in v0.7.0
func (e ECEncryptor) KeyType() KeyType
func (ECEncryptor) Metadata ¶ added in v0.1.8
func (e ECEncryptor) Metadata() (map[string]string, error)
func (ECEncryptor) PublicKeyInPemFormat ¶ added in v0.1.8
func (e ECEncryptor) PublicKeyInPemFormat() (string, error)
PublicKeyInPemFormat Returns public key in pem format.
func (ECEncryptor) Type ¶ added in v0.1.8
func (e ECEncryptor) Type() SchemeType
type ECKeyPair ¶
type ECKeyPair struct {
PrivateKey *ecdsa.PrivateKey
}
func NewECKeyPair ¶
NewECKeyPair Generates an EC key pair of the given bit size.
func (ECKeyPair) GetKeyType ¶ added in v0.1.8
GetKeyType returns the key type (ECKey)
func (ECKeyPair) PrivateKeyInPemFormat ¶
PrivateKeyInPemFormat Returns private key in pem format.
func (ECKeyPair) PublicKeyInPemFormat ¶
PublicKeyInPemFormat Returns public key in pem format.
type Encapsulator ¶ added in v0.4.0
type Encapsulator interface {
// Encapsulate wraps a secret key with the encapsulation key
Encapsulate(dek ProtectedKey) ([]byte, error)
// Encrypt wraps a secret key with the encapsulation key
Encrypt(data []byte) ([]byte, error)
// PublicKeyAsPEM exports the public key, used to encapsulate the value, in Privacy-Enhanced Mail format,
// or the empty string if not present.
PublicKeyAsPEM() (string, error)
// For EC schemes, this method returns the public part of the ephemeral key.
// Otherwise, it returns nil.
EphemeralKey() []byte
}
Encapsulator enables key encapsulation with a public key
type HybridNISTDecryptor ¶ added in v0.11.0
type HybridNISTDecryptor struct {
// contains filtered or unexported fields
}
HybridNISTDecryptor implements PrivateKeyDecryptor for NIST hybrid schemes.
func NewP256MLKEM768Decryptor ¶ added in v0.11.0
func NewP256MLKEM768Decryptor(privateKey []byte) (*HybridNISTDecryptor, error)
func NewP384MLKEM1024Decryptor ¶ added in v0.11.0
func NewP384MLKEM1024Decryptor(privateKey []byte) (*HybridNISTDecryptor, error)
func NewSaltedP256MLKEM768Decryptor ¶ added in v0.11.0
func NewSaltedP256MLKEM768Decryptor(privateKey, salt, info []byte) (*HybridNISTDecryptor, error)
func NewSaltedP384MLKEM1024Decryptor ¶ added in v0.11.0
func NewSaltedP384MLKEM1024Decryptor(privateKey, salt, info []byte) (*HybridNISTDecryptor, error)
type HybridNISTEncryptor ¶ added in v0.11.0
type HybridNISTEncryptor struct {
// contains filtered or unexported fields
}
HybridNISTEncryptor implements PublicKeyEncryptor for NIST hybrid schemes.
func NewP256MLKEM768Encryptor ¶ added in v0.11.0
func NewP256MLKEM768Encryptor(publicKey, salt, info []byte) (*HybridNISTEncryptor, error)
func NewP384MLKEM1024Encryptor ¶ added in v0.11.0
func NewP384MLKEM1024Encryptor(publicKey, salt, info []byte) (*HybridNISTEncryptor, error)
func (*HybridNISTEncryptor) Encrypt ¶ added in v0.11.0
func (e *HybridNISTEncryptor) Encrypt(data []byte) ([]byte, error)
func (*HybridNISTEncryptor) EphemeralKey ¶ added in v0.11.0
func (e *HybridNISTEncryptor) EphemeralKey() []byte
func (*HybridNISTEncryptor) KeyType ¶ added in v0.11.0
func (e *HybridNISTEncryptor) KeyType() KeyType
func (*HybridNISTEncryptor) Metadata ¶ added in v0.11.0
func (e *HybridNISTEncryptor) Metadata() (map[string]string, error)
func (*HybridNISTEncryptor) PublicKeyInPemFormat ¶ added in v0.11.0
func (e *HybridNISTEncryptor) PublicKeyInPemFormat() (string, error)
func (*HybridNISTEncryptor) Type ¶ added in v0.11.0
func (e *HybridNISTEncryptor) Type() SchemeType
type HybridNISTKeyPair ¶ added in v0.11.0
type HybridNISTKeyPair struct {
// contains filtered or unexported fields
}
HybridNISTKeyPair holds a hybrid EC + ML-KEM keypair as raw bytes.
func NewP256MLKEM768KeyPair ¶ added in v0.11.0
func NewP256MLKEM768KeyPair() (HybridNISTKeyPair, error)
func NewP384MLKEM1024KeyPair ¶ added in v0.11.0
func NewP384MLKEM1024KeyPair() (HybridNISTKeyPair, error)
func (HybridNISTKeyPair) GetKeyType ¶ added in v0.11.0
func (k HybridNISTKeyPair) GetKeyType() KeyType
func (HybridNISTKeyPair) PrivateKeyInPemFormat ¶ added in v0.11.0
func (k HybridNISTKeyPair) PrivateKeyInPemFormat() (string, error)
func (HybridNISTKeyPair) PublicKeyInPemFormat ¶ added in v0.11.0
func (k HybridNISTKeyPair) PublicKeyInPemFormat() (string, error)
type HybridNISTWrappedKey ¶ added in v0.11.0
type HybridNISTWrappedKey struct {
HybridCiphertext []byte `asn1:"tag:0"`
EncryptedDEK []byte `asn1:"tag:1"`
}
HybridNISTWrappedKey is the ASN.1 envelope stored in wrapped_key.
type KeyPair ¶ added in v0.1.8
type KeyPair interface {
PublicKeyInPemFormat() (string, error)
PrivateKeyInPemFormat() (string, error)
GetKeyType() KeyType
}
func NewHybridKeyPair ¶ added in v0.11.0
NewHybridKeyPair creates a key pair for the given hybrid key type.
func NewKeyPair ¶ added in v0.1.8
type KeyType ¶ added in v0.1.8
type KeyType string
func ParseKeyType ¶ added in v0.11.0
ParseKeyType validates a string as a known KeyType, returning an error for unrecognized values.
type PrivateKeyDecryptor ¶ added in v0.1.8
type PrivateKeyDecryptor interface {
// Decrypt decrypts ciphertext with private key.
Decrypt(data []byte) ([]byte, error)
}
func FromPrivatePEM ¶ added in v0.1.8
func FromPrivatePEM(privateKeyInPem string) (PrivateKeyDecryptor, error)
FromPrivatePEM creates and returns a new AsymDecryption.
func FromPrivatePEMWithSalt ¶ added in v0.2.0
func FromPrivatePEMWithSalt(privateKeyInPem string, salt, info []byte) (PrivateKeyDecryptor, error)
type ProtectedKey ¶ added in v0.4.0
type ProtectedKey interface {
// VerifyBinding checks if the policy binding matches the given policy data
VerifyBinding(ctx context.Context, policy, policyBinding []byte) error
// Export returns the raw key data, optionally encrypting it with the provided encapsulator
//
// Deprecated: Use the Encapsulator's Encapsulate method instead.
Export(encapsulator Encapsulator) ([]byte, error)
// DecryptAESGCM decrypts encrypted policies and metadata
DecryptAESGCM(iv []byte, body []byte, tagSize int) ([]byte, error)
}
ProtectedKey represents a decrypted key with operations that can be performed on it
type PublicKeyEncryptor ¶ added in v0.1.8
type PublicKeyEncryptor interface {
// Encrypt encrypts data with public key.
Encrypt(data []byte) ([]byte, error)
// PublicKeyInPemFormat Returns public key in pem format, or the empty string if not present
PublicKeyInPemFormat() (string, error)
// Type required to use the scheme for encryption - notably, if it procduces extra metadata.
Type() SchemeType
// KeyType returns the key type, e.g. RSA or EC.
KeyType() KeyType
// For EC schemes, this method returns the public part of the ephemeral key.
// Otherwise, it returns nil.
EphemeralKey() []byte
// Any extra metadata, e.g. the ephemeral public key for EC scheme keys.
Metadata() (map[string]string, error)
}
func FromPublicPEM ¶ added in v0.1.8
func FromPublicPEM(publicKeyInPem string) (PublicKeyEncryptor, error)
func FromPublicPEMWithSalt ¶ added in v0.2.0
func FromPublicPEMWithSalt(publicKeyInPem string, salt, info []byte) (PublicKeyEncryptor, error)
type RsaKeyPair ¶
type RsaKeyPair struct {
// contains filtered or unexported fields
}
func FromRSA ¶ added in v0.1.4
func FromRSA(k *rsa.PrivateKey) RsaKeyPair
func NewRSAKeyPair ¶
func NewRSAKeyPair(bits int) (RsaKeyPair, error)
NewRSAKeyPair Generates an RSA key pair of the given bit size.
func (RsaKeyPair) GetKeyType ¶ added in v0.1.8
func (keyPair RsaKeyPair) GetKeyType() KeyType
GetKeyType returns the key type (RSAKey)
func (RsaKeyPair) KeySize ¶
func (keyPair RsaKeyPair) KeySize() (int, error)
KeySize Return the size of this rsa key pair.
func (RsaKeyPair) PrivateKeyInPemFormat ¶
func (keyPair RsaKeyPair) PrivateKeyInPemFormat() (string, error)
PrivateKeyInPemFormat Returns private key in pem format.
func (RsaKeyPair) PublicKeyInPemFormat ¶
func (keyPair RsaKeyPair) PublicKeyInPemFormat() (string, error)
PublicKeyInPemFormat Returns public key in pem format.
type SchemeType ¶ added in v0.1.8
type SchemeType string
const ( RSA SchemeType = "wrapped" EC SchemeType = "ec-wrapped" Hybrid SchemeType = "hybrid-wrapped" )
type XWingDecryptor ¶ added in v0.11.0
type XWingDecryptor struct {
// contains filtered or unexported fields
}
func NewSaltedXWingDecryptor ¶ added in v0.11.0
func NewSaltedXWingDecryptor(privateKey, salt, info []byte) (*XWingDecryptor, error)
func NewXWingDecryptor ¶ added in v0.11.0
func NewXWingDecryptor(privateKey []byte) (*XWingDecryptor, error)
type XWingEncryptor ¶ added in v0.11.0
type XWingEncryptor struct {
// contains filtered or unexported fields
}
func NewXWingEncryptor ¶ added in v0.11.0
func NewXWingEncryptor(publicKey, salt, info []byte) (*XWingEncryptor, error)
func (*XWingEncryptor) Encrypt ¶ added in v0.11.0
func (e *XWingEncryptor) Encrypt(data []byte) ([]byte, error)
func (*XWingEncryptor) EphemeralKey ¶ added in v0.11.0
func (e *XWingEncryptor) EphemeralKey() []byte
func (*XWingEncryptor) KeyType ¶ added in v0.11.0
func (e *XWingEncryptor) KeyType() KeyType
func (*XWingEncryptor) Metadata ¶ added in v0.11.0
func (e *XWingEncryptor) Metadata() (map[string]string, error)
func (*XWingEncryptor) PublicKeyInPemFormat ¶ added in v0.11.0
func (e *XWingEncryptor) PublicKeyInPemFormat() (string, error)
func (*XWingEncryptor) Type ¶ added in v0.11.0
func (e *XWingEncryptor) Type() SchemeType
type XWingKeyPair ¶ added in v0.11.0
type XWingKeyPair struct {
// contains filtered or unexported fields
}
func NewXWingKeyPair ¶ added in v0.11.0
func NewXWingKeyPair() (XWingKeyPair, error)
func (XWingKeyPair) GetKeyType ¶ added in v0.11.0
func (k XWingKeyPair) GetKeyType() KeyType
func (XWingKeyPair) PrivateKeyInPemFormat ¶ added in v0.11.0
func (k XWingKeyPair) PrivateKeyInPemFormat() (string, error)
func (XWingKeyPair) PublicKeyInPemFormat ¶ added in v0.11.0
func (k XWingKeyPair) PublicKeyInPemFormat() (string, error)