Documentation ¶
Index ¶
- Variables
- func CatalogDecrypt(key, data []byte, catalog interface{}) error
- func CatalogEncrypt(catalog interface{}) ([]byte, []byte, error)
- func CreateCatalogKey() ([]byte, error)
- func Decrypt(key PrivKey, txID string, message []byte) ([]byte, error)
- func DualKeyGetSecret(priv PrivKey, txID TransactionID) ([]byte, bool, error)
- func EdPrivToX25519(privateKey ed25519.PrivateKey) []byte
- func EdPubToX25519(pk ed25519.PublicKey) []byte
- func Encrypt(pubKey PubKey, message []byte) ([]byte, string, string, error)
- func GenerateIvAndKey() ([]byte, []byte, error)
- func GenerateKeyPair(kt KeyType) (*PrivKey, *PubKey, error)
- func GetAesDecryptorReader(iv []byte, key []byte, r io.Reader) (io.Reader, error)
- func GetAesEncryptorReader(iv []byte, key []byte, r io.Reader) (io.Reader, error)
- func JSONDecrypt(key []byte, ciphertext []byte, v interface{}) error
- func JSONEncrypt(key []byte, data interface{}) ([]byte, error)
- func KeyExchange(privK PrivKey, pubK PubKey) ([]byte, error)
- func MessageDecrypt(key []byte, message []byte) ([]byte, error)
- func MessageEncrypt(key []byte, plaintext []byte) ([]byte, error)
- func Sign(key PrivKey, message []byte) ([]byte, error)
- func Verify(key PubKey, message []byte, sig []byte) (bool, error)
- type KeyEcdsa
- func (k *KeyEcdsa) CanDualKeyExchange() bool
- func (k *KeyEcdsa) CanEncrypt() bool
- func (k *KeyEcdsa) CanKeyExchange() bool
- func (k *KeyEcdsa) Decrypt(key PrivKey, txID string, message []byte) ([]byte, error)
- func (k *KeyEcdsa) DualKeyExchange(pub PubKey) ([]byte, *TransactionID, error)
- func (k *KeyEcdsa) Encrypt(key PubKey, message []byte) ([]byte, string, string, error)
- func (k *KeyEcdsa) GenerateKeyPair(r io.Reader) (*PrivKey, *PubKey, error)
- func (k *KeyEcdsa) JWTHasValidSignMethod(token *jwt.Token) bool
- func (k *KeyEcdsa) JWTSignMethod() jwt.SigningMethod
- func (k *KeyEcdsa) KeyExchange(privK PrivKey, pubK PubKey) ([]byte, error)
- func (k *KeyEcdsa) ParsePrivateKeyData(buf []byte) (interface{}, error)
- func (k *KeyEcdsa) ParsePrivateKeyInterface(key interface{}) ([]byte, error)
- func (k *KeyEcdsa) ParsePublicKeyData(buf []byte) (interface{}, error)
- func (k *KeyEcdsa) ParsePublicKeyInterface(key interface{}) ([]byte, error)
- func (k *KeyEcdsa) Sign(_ io.Reader, key PrivKey, message []byte) ([]byte, error)
- func (k *KeyEcdsa) String() string
- func (k *KeyEcdsa) Verify(key PubKey, message []byte, sig []byte) (bool, error)
- type KeyEd25519
- func (k *KeyEd25519) CanDualKeyExchange() bool
- func (k *KeyEd25519) CanEncrypt() bool
- func (k *KeyEd25519) CanKeyExchange() bool
- func (k *KeyEd25519) Decrypt(key PrivKey, txID string, message []byte) ([]byte, error)
- func (k *KeyEd25519) DualKeyExchange(pub PubKey) ([]byte, *TransactionID, error)
- func (k *KeyEd25519) Encrypt(key PubKey, message []byte) ([]byte, string, string, error)
- func (k *KeyEd25519) GenerateKeyPair(r io.Reader) (*PrivKey, *PubKey, error)
- func (k *KeyEd25519) JWTHasValidSignMethod(token *jwt.Token) bool
- func (k *KeyEd25519) JWTSignMethod() jwt.SigningMethod
- func (k *KeyEd25519) KeyExchange(privK PrivKey, pubK PubKey) ([]byte, error)
- func (k *KeyEd25519) ParsePrivateKeyData(buf []byte) (interface{}, error)
- func (k *KeyEd25519) ParsePrivateKeyInterface(key interface{}) ([]byte, error)
- func (k *KeyEd25519) ParsePublicKeyData(buf []byte) (interface{}, error)
- func (k *KeyEd25519) ParsePublicKeyInterface(key interface{}) ([]byte, error)
- func (k *KeyEd25519) Sign(reader io.Reader, key PrivKey, message []byte) ([]byte, error)
- func (k *KeyEd25519) String() string
- func (k *KeyEd25519) Verify(key PubKey, message []byte, sig []byte) (bool, error)
- type KeyPair
- type KeyRsa
- func (k *KeyRsa) CanDualKeyExchange() bool
- func (k *KeyRsa) CanEncrypt() bool
- func (k *KeyRsa) CanKeyExchange() bool
- func (k *KeyRsa) Decrypt(key PrivKey, _ string, message []byte) ([]byte, error)
- func (k *KeyRsa) DualKeyExchange(_ PubKey) ([]byte, *TransactionID, error)
- func (k *KeyRsa) Encrypt(key PubKey, message []byte) ([]byte, string, string, error)
- func (k *KeyRsa) GenerateKeyPair(r io.Reader) (*PrivKey, *PubKey, error)
- func (k *KeyRsa) JWTHasValidSignMethod(token *jwt.Token) bool
- func (k *KeyRsa) JWTSignMethod() jwt.SigningMethod
- func (k *KeyRsa) KeyExchange(_ PrivKey, _ PubKey) ([]byte, error)
- func (k *KeyRsa) ParsePrivateKeyData(buf []byte) (interface{}, error)
- func (k *KeyRsa) ParsePrivateKeyInterface(key interface{}) ([]byte, error)
- func (k *KeyRsa) ParsePublicKeyData(buf []byte) (interface{}, error)
- func (k *KeyRsa) ParsePublicKeyInterface(key interface{}) ([]byte, error)
- func (k *KeyRsa) Sign(_ io.Reader, key PrivKey, message []byte) ([]byte, error)
- func (k *KeyRsa) String() string
- func (k *KeyRsa) Verify(key PubKey, message []byte, sig []byte) (bool, error)
- type KeyType
- type PrivKey
- type PubKey
- type SigningMethodEdDSA
- type TransactionID
Constants ¶
This section is empty.
Variables ¶
var KeyTypes = []KeyType{ NewRsaKey(2048), NewRsaKey(4096), NewEd25519Key(), NewEcdsaKey(elliptic.P384()), }
KeyTypes is a list of all keytypes available
Functions ¶
func CatalogDecrypt ¶
CatalogDecrypt decrypts a catalog with the given key
func CatalogEncrypt ¶
CatalogEncrypt encrypts a catalog with a random key.
func CreateCatalogKey ¶
CreateCatalogKey generates a new key that is used for encrypting a catalog
func DualKeyGetSecret ¶
func DualKeyGetSecret(priv PrivKey, txID TransactionID) ([]byte, bool, error)
DualKeyGetSecret verifies if the transaction ID matches our private key. If so, it will return the secret that has been exchanged
func EdPrivToX25519 ¶
func EdPrivToX25519(privateKey ed25519.PrivateKey) []byte
EdPrivToX25519 converts a ed25519 PrivateKey to a X25519 Private Key
func EdPubToX25519 ¶
EdPubToX25519 converts a ed25519 Public Key to a X25519 Public Key
func GenerateIvAndKey ¶
GenerateIvAndKey generate a random IV and key
func GenerateKeyPair ¶
GenerateKeyPair generates a private/public keypair based on the given type
func GetAesDecryptorReader ¶
GetAesDecryptorReader returns a reader that automatically decrypts reader blocks through CFB stream
func GetAesEncryptorReader ¶
GetAesEncryptorReader returns a reader that automatically encrypts reader blocks through CFB stream
func JSONDecrypt ¶
JSONDecrypt decrypts data back from a encrypted marshalled JSON structure
func JSONEncrypt ¶
JSONEncrypt encrypts a structure that is marshalled to JSON
func KeyExchange ¶
KeyExchange exchange a message given the Private and other's Public Key
func MessageDecrypt ¶
MessageDecrypt decrypts a binary message
func MessageEncrypt ¶
MessageEncrypt encrypts a binary message
Types ¶
type KeyEcdsa ¶
KeyEcdsa is a keytype for elliptic curve
func (*KeyEcdsa) CanDualKeyExchange ¶
CanDualKeyExchange returns true if the key(type) is able to be used for a dual key exchange
func (*KeyEcdsa) CanEncrypt ¶
CanEncrypt returns true if the key(type) is able to be used for encryption/decryption
func (*KeyEcdsa) CanKeyExchange ¶
CanKeyExchange returns true if the key(type) is able to be used for key exchange
func (*KeyEcdsa) DualKeyExchange ¶
func (k *KeyEcdsa) DualKeyExchange(pub PubKey) ([]byte, *TransactionID, error)
DualKeyExchange allows for a ECIES key exchange
func (*KeyEcdsa) Encrypt ¶
Encrypt will encrypt the given bytes with the public key. Will return the ciphertext, a transaction ID (if needed), the crypto used and an error
func (*KeyEcdsa) GenerateKeyPair ¶
GenerateKeyPair will generate a new keypair for this keytype. io.Reader can be deterministic if needed
func (*KeyEcdsa) JWTHasValidSignMethod ¶
JWTHasValidSignMethod will return true when this keytype has been used for signing the token
func (*KeyEcdsa) JWTSignMethod ¶
func (k *KeyEcdsa) JWTSignMethod() jwt.SigningMethod
JWTSignMethod will return the signing method used for this keytype
func (*KeyEcdsa) KeyExchange ¶
KeyExchange allows for a key exchange (if possible in the keytype)
func (*KeyEcdsa) ParsePrivateKeyData ¶
ParsePrivateKeyData will parse a string representation of a key and returns the given key
func (*KeyEcdsa) ParsePrivateKeyInterface ¶
ParsePrivateKeyInterface will parse a interface and returns the key representation
func (*KeyEcdsa) ParsePublicKeyData ¶
ParsePublicKeyData will parse a interface and returns the key representation
func (*KeyEcdsa) ParsePublicKeyInterface ¶
ParsePublicKeyInterface will parse a interface and returns the key representation
type KeyEd25519 ¶
type KeyEd25519 struct { }
KeyEd25519 is the ed25519 keytype
func (*KeyEd25519) CanDualKeyExchange ¶
func (k *KeyEd25519) CanDualKeyExchange() bool
CanDualKeyExchange returns true if the key(type) is able to be used for a dual key exchange
func (*KeyEd25519) CanEncrypt ¶
func (k *KeyEd25519) CanEncrypt() bool
CanEncrypt returns true if the key(type) is able to be used for encryption/decryption
func (*KeyEd25519) CanKeyExchange ¶
func (k *KeyEd25519) CanKeyExchange() bool
CanKeyExchange returns true if the key(type) is able to be used for key exchange
func (*KeyEd25519) DualKeyExchange ¶
func (k *KeyEd25519) DualKeyExchange(pub PubKey) ([]byte, *TransactionID, error)
DualKeyExchange allows for a ECIES key exchange
func (*KeyEd25519) Encrypt ¶
Encrypt will encrypt the given bytes with the public key. Will return the ciphertext, a transaction ID (if needed), the crypto used and an error
func (*KeyEd25519) GenerateKeyPair ¶
GenerateKeyPair will generate a new keypair for this keytype. io.Reader can be deterministic if needed
func (*KeyEd25519) JWTHasValidSignMethod ¶
func (k *KeyEd25519) JWTHasValidSignMethod(token *jwt.Token) bool
JWTHasValidSignMethod will return true when this keytype has been used for signing the token
func (*KeyEd25519) JWTSignMethod ¶
func (k *KeyEd25519) JWTSignMethod() jwt.SigningMethod
JWTSignMethod will return the signing method used for this keytype
func (*KeyEd25519) KeyExchange ¶
func (k *KeyEd25519) KeyExchange(privK PrivKey, pubK PubKey) ([]byte, error)
KeyExchange allows for a key exchange (if possible in the keytype)
func (*KeyEd25519) ParsePrivateKeyData ¶
func (k *KeyEd25519) ParsePrivateKeyData(buf []byte) (interface{}, error)
ParsePrivateKeyData will parse a string representation of a key and returns the given key
func (*KeyEd25519) ParsePrivateKeyInterface ¶
func (k *KeyEd25519) ParsePrivateKeyInterface(key interface{}) ([]byte, error)
ParsePrivateKeyInterface will parse a interface and returns the key representation
func (*KeyEd25519) ParsePublicKeyData ¶
func (k *KeyEd25519) ParsePublicKeyData(buf []byte) (interface{}, error)
ParsePublicKeyData will parse a interface and returns the key representation
func (*KeyEd25519) ParsePublicKeyInterface ¶
func (k *KeyEd25519) ParsePublicKeyInterface(key interface{}) ([]byte, error)
ParsePublicKeyInterface will parse a interface and returns the key representation
func (*KeyEd25519) String ¶
func (k *KeyEd25519) String() string
String returns a string representation of the key type ("rsa", "ecdsa", "ed25519" etc)
type KeyPair ¶
type KeyPair struct { Generator string `json:"generator"` // The generator string that will generate the given keypair FingerPrint string `json:"fingerprint"` // The sha1 fingerprint for this key PrivKey PrivKey `json:"priv_key"` // PEM encoded private key PubKey PubKey `json:"pub_key"` // PEM encoded public key }
KeyPair is a structure with key information
type KeyRsa ¶
KeyRsa is the RSA keytype
func (*KeyRsa) CanDualKeyExchange ¶
CanDualKeyExchange returns true if the key(type) is able to be used for a dual key exchange
func (*KeyRsa) CanEncrypt ¶
CanEncrypt returns true if the key(type) is able to be used for encryption/decryption
func (*KeyRsa) CanKeyExchange ¶
CanKeyExchange returns true if the key(type) is able to be used for key exchange
func (*KeyRsa) DualKeyExchange ¶
func (k *KeyRsa) DualKeyExchange(_ PubKey) ([]byte, *TransactionID, error)
DualKeyExchange allows for a ECIES key exchange
func (*KeyRsa) Encrypt ¶
Encrypt will encrypt the given bytes with the public key. Will return the ciphertext, a transaction ID (if needed), the crypto used and an error
func (*KeyRsa) GenerateKeyPair ¶
GenerateKeyPair will generate a new keypair for this keytype. io.Reader can be deterministic if needed
func (*KeyRsa) JWTHasValidSignMethod ¶
JWTHasValidSignMethod will return true when this keytype has been used for signing the token
func (*KeyRsa) JWTSignMethod ¶
func (k *KeyRsa) JWTSignMethod() jwt.SigningMethod
JWTSignMethod will return the signing method used for this keytype
func (*KeyRsa) KeyExchange ¶
KeyExchange allows for a key exchange (if possible in the keytype)
func (*KeyRsa) ParsePrivateKeyData ¶
ParsePrivateKeyData will parse a string representation of a key and returns the given key
func (*KeyRsa) ParsePrivateKeyInterface ¶
ParsePrivateKeyInterface will parse a interface and returns the key representation
func (*KeyRsa) ParsePublicKeyData ¶
ParsePublicKeyData will parse a interface and returns the key representation
func (*KeyRsa) ParsePublicKeyInterface ¶
ParsePublicKeyInterface will parse a interface and returns the key representation
type KeyType ¶
type KeyType interface { // CanEncrypt returns true if the key(type) is able to be used for encryption/decryption CanEncrypt() bool // CanKeyExchange returns true if the key(type) is able to be used for key exchange CanKeyExchange() bool // CanDualKeyExchange returns true if the key(type) is able to be used for a dual key exchange CanDualKeyExchange() bool // String returns a string representation of the key type ("rsa", "ecdsa", "ed25519" etc) String() string // ParsePrivateKeyData will parse a string representation of a key and returns the given key ParsePrivateKeyData([]byte) (interface{}, error) // ParsePrivateKeyInterface will parse a interface and returns the key representation ParsePrivateKeyInterface(interface{}) ([]byte, error) // ParsePublicKeyData will parse a interface and returns the key representation ParsePublicKeyData([]byte) (interface{}, error) // ParsePublicKeyInterface will parse a interface and returns the key representation ParsePublicKeyInterface(interface{}) ([]byte, error) // GenerateKeyPair will generate a new keypair for this keytype. io.Reader can be deterministic if needed GenerateKeyPair(io.Reader) (*PrivKey, *PubKey, error) // JWTSignMethod will return the signing method used for this keytype JWTSignMethod() jwt.SigningMethod // JWTHasValidSignMethod will return true when this keytype has been used for signing the token JWTHasValidSignMethod(*jwt.Token) bool // Encrypt will encrypt the given bytes with the public key. Will return the ciphertext, a transaction ID (if needed), the crypto used and an error Encrypt(PubKey, []byte) ([]byte, string, string, error) // Decrypt will decrypt the given bytes with the private key Decrypt(PrivKey, string, []byte) ([]byte, error) // Sign will sign the given bytes with the private key Sign(io.Reader, PrivKey, []byte) ([]byte, error) // Verify will verify the signature with the public key Verify(PubKey, []byte, []byte) (bool, error) // KeyExchange allows for a key exchange (if possible in the keytype) KeyExchange(privK PrivKey, pubK PubKey) ([]byte, error) // DualKeyExchange allows for a ECIES key exchange DualKeyExchange(_ PubKey) ([]byte, *TransactionID, error) }
KeyType is an interface that each key type should implement.
func FindKeyType ¶
FindKeyType finds the keytype based on the given string
func NewEcdsaKey ¶
NewEcdsaKey creates a new keytype based on the given curve
func NewEd25519Key ¶
func NewEd25519Key() KeyType
NewEd25519Key will return the keytype of ed25519. There is only a single curve here.
type PrivKey ¶
type PrivKey struct { Type KeyType // structure of the key S string // String representation <type> <PEM key> B []byte // Byte representation of string K interface{} // Key interface{} }
PrivKey is a structure containing a private key in multiple formats
func PrivateKeyFromInterface ¶
PrivateKeyFromInterface creates a new key based on an interface{} (like rsa.PrivateKey)
func PrivateKeyFromString ¶
PrivateKeyFromString creates a new private key based on the string data "<type> <key>"
func (*PrivKey) MarshalJSON ¶
MarshalJSON marshals a key into bytes
func (*PrivKey) UnmarshalJSON ¶
UnmarshalJSON unmarshals bytes into a key
type PubKey ¶
type PubKey struct { Type KeyType // Type of the the private key S string // String representation <type> <PEM key> <description> B []byte // Byte representation of string K interface{} // Key interface{} Description string // Optional description }
PubKey is a structure containing a public key in multiple formats
func PublicKeyFromInterface ¶
PublicKeyFromInterface creates a new key based on an interface{} (like rsa.PublicKey)
func PublicKeyFromString ¶
PublicKeyFromString creates a new public key based on the string data "<type> <key> <description>"
func (*PubKey) Fingerprint ¶
Fingerprint return the fingerprint of the key
func (*PubKey) MarshalJSON ¶
MarshalJSON marshals a key into bytes
func (*PubKey) UnmarshalJSON ¶
UnmarshalJSON unmarshals bytes into a key
type SigningMethodEdDSA ¶
type SigningMethodEdDSA struct{}
SigningMethodEdDSA ed25519 signing method for JWT token signing
func (*SigningMethodEdDSA) Alg ¶
func (m *SigningMethodEdDSA) Alg() string
Alg returns the algorithm used
type TransactionID ¶
TransactionID is a structure that holds the P and R value that is needed to verify the dual key signature
func DualKeyExchange ¶
func DualKeyExchange(pub PubKey) ([]byte, *TransactionID, error)
DualKeyExchange is a Dual DH key exchange that uses an intermediate key. This key is randomized and provide a way for alice and bob to communicate through a non-deterministic DH. It returns the (shared) secret, a transaction ID that needs to be send over to the other user.
func TxIDFromString ¶
func TxIDFromString(s string) (*TransactionID, error)
TxIDFromString converts a hexadecimal presentation into a TransactionID
func (TransactionID) ToHex ¶
func (txID TransactionID) ToHex() string
ToHex converts a transaction ID to a hexadecimal representation