Documentation ¶
Index ¶
- Variables
- func AddKeySetFile(filename string, key PublicKey) error
- func SaveKey(filename string, key PrivateKey) error
- func SavePublicKey(filename string, key PublicKey) error
- type PrivateKey
- func FromCryptoPrivateKey(cryptoPrivateKey crypto.PrivateKey) (PrivateKey, error)
- func GenerateECP256PrivateKey() (PrivateKey, error)
- func GenerateECP384PrivateKey() (PrivateKey, error)
- func GenerateECP521PrivateKey() (PrivateKey, error)
- func GenerateRSA2048PrivateKey() (PrivateKey, error)
- func GenerateRSA3072PrivateKey() (PrivateKey, error)
- func GenerateRSA4096PrivateKey() (PrivateKey, error)
- func LoadKeyFile(filename string) (PrivateKey, error)
- func UnmarshalPrivateKeyJWK(data []byte) (PrivateKey, error)
- func UnmarshalPrivateKeyPEM(data []byte) (PrivateKey, error)
- type PublicKey
- func FromCryptoPublicKey(cryptoPublicKey crypto.PublicKey) (PublicKey, error)
- func LoadKeySetFile(filename string) ([]PublicKey, error)
- func LoadPublicKeyFile(filename string) (PublicKey, error)
- func UnmarshalPublicKeyJWK(data []byte) (PublicKey, error)
- func UnmarshalPublicKeyJWKSet(data []byte) ([]PublicKey, error)
- func UnmarshalPublicKeyPEM(data []byte) (PublicKey, error)
- func UnmarshalPublicKeyPEMBundle(data []byte) ([]PublicKey, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKeyFileDoesNotExist indicates that the private key file does not exist. ErrKeyFileDoesNotExist = errors.New("key file does not exist") )
Functions ¶
func AddKeySetFile ¶
AddKeySetFile adds a key to a key set
func SaveKey ¶
func SaveKey(filename string, key PrivateKey) error
SaveKey saves the given key to a file using the provided filename. This process will overwrite any existing file at the provided location.
func SavePublicKey ¶
SavePublicKey saves the given public key to the file.
Types ¶
type PrivateKey ¶
type PrivateKey interface { // A PrivateKey contains all fields and methods of a PublicKey of the // same type. The MarshalJSON method also outputs the private key as a // JSON Web Key, and the PEMBlock method outputs the private key as a // PEM block. PublicKey // PublicKey returns the PublicKey associated with this PrivateKey. PublicKey() PublicKey // Sign signs the data read from the io.Reader using a signature algorithm // supported by the private key. If the specified hashing algorithm is // supported by this key, that hash function is used to generate the // signature otherwise the the default hashing algorithm for this key is // used. Returns the signature and identifier of the algorithm used. Sign(data io.Reader, hashID crypto.Hash) (signature []byte, alg string, err error) // CryptoPrivateKey returns the internal object which can be used as a // crypto.PublicKey for use with other standard library operations. The // type is either *rsa.PublicKey or *ecdsa.PublicKey CryptoPrivateKey() crypto.PrivateKey }
PrivateKey is a generic interface for a Private Key.
func FromCryptoPrivateKey ¶
func FromCryptoPrivateKey(cryptoPrivateKey crypto.PrivateKey) (PrivateKey, error)
FromCryptoPrivateKey returns a libtrust PrivateKey representation of the given *ecdsa.PrivateKey or *rsa.PrivateKey. Returns a non-nil error when the given key is of an unsupported type.
func GenerateECP256PrivateKey ¶
func GenerateECP256PrivateKey() (PrivateKey, error)
GenerateECP256PrivateKey generates a key pair using elliptic curve P-256.
func GenerateECP384PrivateKey ¶
func GenerateECP384PrivateKey() (PrivateKey, error)
GenerateECP384PrivateKey generates a key pair using elliptic curve P-384.
func GenerateECP521PrivateKey ¶
func GenerateECP521PrivateKey() (PrivateKey, error)
GenerateECP521PrivateKey generates aß key pair using elliptic curve P-521.
func GenerateRSA2048PrivateKey ¶
func GenerateRSA2048PrivateKey() (PrivateKey, error)
GenerateRSA2048PrivateKey generates a key pair using 2048-bit RSA.
func GenerateRSA3072PrivateKey ¶
func GenerateRSA3072PrivateKey() (PrivateKey, error)
GenerateRSA3072PrivateKey generates a key pair using 3072-bit RSA.
func GenerateRSA4096PrivateKey ¶
func GenerateRSA4096PrivateKey() (PrivateKey, error)
GenerateRSA4096PrivateKey generates a key pair using 4096-bit RSA.
func LoadKeyFile ¶
func LoadKeyFile(filename string) (PrivateKey, error)
LoadKeyFile opens the given filename and attempts to read a Private Key encoded in either PEM or JWK format (if .json or .jwk file extension).
func UnmarshalPrivateKeyJWK ¶
func UnmarshalPrivateKeyJWK(data []byte) (PrivateKey, error)
UnmarshalPrivateKeyJWK unmarshals the given JSON Web Key into a generic Private Key to be used with libtrust.
func UnmarshalPrivateKeyPEM ¶
func UnmarshalPrivateKeyPEM(data []byte) (PrivateKey, error)
UnmarshalPrivateKeyPEM parses the PEM encoded data and returns a libtrust PrivateKey or an error if there is a problem with the encoding.
type PublicKey ¶
type PublicKey interface { // KeyType returns the key type for this key. For elliptic curve keys, // this value should be "EC". For RSA keys, this value should be "RSA". KeyType() string // KeyID returns a distinct identifier which is unique to this Public Key. // The format generated by this library is a base32 encoding of a 240 bit // hash of the public key data divided into 12 groups like so: // ABCD:EFGH:IJKL:MNOP:QRST:UVWX:YZ23:4567:ABCD:EFGH:IJKL:MNOP KeyID() string // Verify verifyies the signature of the data in the io.Reader using this // Public Key. The alg parameter should identify the digital signature // algorithm which was used to produce the signature and should be // supported by this public key. Returns a nil error if the signature // is valid. Verify(data io.Reader, alg string, signature []byte) error // CryptoPublicKey returns the internal object which can be used as a // crypto.PublicKey for use with other standard library operations. The type // is either *rsa.PublicKey or *ecdsa.PublicKey CryptoPublicKey() crypto.PublicKey // These public keys can be serialized to the standard JSON encoding for // JSON Web Keys. See section 6 of the IETF draft RFC for JOSE JSON Web // Algorithms. MarshalJSON() ([]byte, error) // These keys can also be serialized to the standard PEM encoding. PEMBlock() (*pem.Block, error) // The string representation of a key is its key type and ID. String() string AddExtendedField(string, interface{}) GetExtendedField(string) interface{} }
PublicKey is a generic interface for a Public Key.
func FromCryptoPublicKey ¶
FromCryptoPublicKey returns a libtrust PublicKey representation of the given *ecdsa.PublicKey or *rsa.PublicKey. Returns a non-nil error when the given key is of an unsupported type.
func LoadKeySetFile ¶
LoadKeySetFile loads a key set
func LoadPublicKeyFile ¶
LoadPublicKeyFile opens the given filename and attempts to read a Public Key encoded in either PEM or JWK format (if .json or .jwk file extension).
func UnmarshalPublicKeyJWK ¶
UnmarshalPublicKeyJWK unmarshals the given JSON Web Key into a generic Public Key to be used with libtrust.
func UnmarshalPublicKeyJWKSet ¶
UnmarshalPublicKeyJWKSet parses the JSON encoded data as a JSON Web Key Set and returns a slice of Public Key objects.
func UnmarshalPublicKeyPEM ¶
UnmarshalPublicKeyPEM parses the PEM encoded data and returns a libtrust PublicKey or an error if there is a problem with the encoding.
func UnmarshalPublicKeyPEMBundle ¶
UnmarshalPublicKeyPEMBundle parses the PEM encoded data as a bundle of PEM blocks appended one after the other and returns a slice of PublicKey objects that it finds.