Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeECDSASecretKey(sk *ecdsa.PrivateKey) ([]byte, error)
- func EncodeED25519SecretKey(sk *ed25519.PrivateKey) ([]byte, error)
- func EncodePublicKey(pub crypto.PublicKey) ([]byte, error)
- func EncodeRSASecretKey(sk *rsa.PrivateKey) ([]byte, error)
- func EncodeSecretkey(priv crypto.PrivateKey) ([]byte, error)
- func GenerateKey(algo x509.PublicKeyAlgorithm) (pubBytes []byte, privBytes []byte, err error)
- func MarshalPKIXPublicKey(pub crypto.PublicKey) ([]byte, error)
- func NewECDSAKeyPair() (crypto.PublicKey, *ecdsa.PrivateKey, error)
- func NewEd25519KeyPair() (crypto.PublicKey, *ed25519.PrivateKey, error)
- func NewRSAKeyPair() (crypto.PublicKey, *rsa.PrivateKey, error)
- func ParseECDSAPKCS8Key(sk []byte) (*ecdsa.PrivateKey, *ecdsa.PublicKey, error)
- func ParsePKIXPublicKey(pk []byte) (crypto.PublicKey, *pkix.AlgorithmIdentifier, error)
- func ParsePublicKey(pk []byte) (crypto.PublicKey, *pkix.AlgorithmIdentifier, error)
- func ParseRSAPKCS8Key(sk []byte) (*rsa.PrivateKey, *rsa.PublicKey, error)
- func ParseSecretKey(sk []byte) (priv crypto.PrivateKey, pub crypto.PublicKey, err error)
- func UnmarshalED25519Key(sk []byte) (*ed25519.PrivateKey, *ed25519.PublicKey, error)
Constants ¶
const ( // ECDSASecretPEMLabel is the label of a PEM-encoded ECDSA secret key. ECDSASecretPEMLabel = "EC PRIVATE KEY" // ECDSAPublicPEMLabel is the label of a PEM-encoded ECDSA public key. ECDSAPublicPEMLabel = "EC PUBLIC KEY" )
const ( // ED25519SecretPEMLabel is the label of a PEM-encoded ED25519 secret key. ED25519SecretPEMLabel = "ED25519 PRIVATE KEY" // ED25519PublicPEMLabel is the label of a PEM-encoded ED25519 public key. ED25519PublicPEMLabel = "ED25519 PUBLIC KEY" )
const ( // GenericPublicPEMLabel is the label of the PEM key in case the key algoritm is not identified. GenericPublicPEMLabel = "PUBLIC KEY" // ED25519 is a public key algorithm currently not supported in x509 ED25519 x509.PublicKeyAlgorithm = iota + 1000 )
const ( // RSAKeySize is the size of the created RSA key. This is not yet configurable but it should be in the future. RSAKeySize = 2048 // RSASecretPEMLabel is the label of a PEM-encoded RSA secret key. RSASecretPEMLabel = "RSA PRIVATE KEY" // RSAPublicPEMLabel is the label of a PEM-encoded RSA public key. RSAPublicPEMLabel = "RSA PUBLIC KEY" )
Variables ¶
var ( // ErrNotImplemented is the error returned if the key algorithm is not implemented. ErrNotImplemented = errors.New("key algorithm not implemented") // HandledPublicKeys are the public keys which we are able to parse HandledPublicKeys = []string{ED25519PublicPEMLabel, ECDSAPublicPEMLabel, RSAPublicPEMLabel, GenericPublicPEMLabel} )
var ( OIDPublicKeyRSA = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 1} OIDPublicKeyDSA = asn1.ObjectIdentifier{1, 2, 840, 10040, 4, 1} OIDPublicKeyECDSA = asn1.ObjectIdentifier{1, 2, 840, 10045, 2, 1} OIDPublicKeyED25519 = asn1.ObjectIdentifier{1, 3, 101, 112} )
List of object identifiers for public keys.
Functions ¶
func EncodeECDSASecretKey ¶
func EncodeECDSASecretKey(sk *ecdsa.PrivateKey) ([]byte, error)
EncodeECDSASecretKey encodes an ECDSA secret key in ASN.1 DER format within a PEM block embedded in PKCS#8.
func EncodeED25519SecretKey ¶
func EncodeED25519SecretKey(sk *ed25519.PrivateKey) ([]byte, error)
EncodeED25519SecretKey encodes an ed25519 secret key using ASN.1
func EncodePublicKey ¶
EncodePublicKey serializes a public key to the PEM format.
func EncodeRSASecretKey ¶
func EncodeRSASecretKey(sk *rsa.PrivateKey) ([]byte, error)
EncodeRSASecretKey encodes an RSA key in ASN.1 DER format within a PEM block embedded in PKCS#8.
func EncodeSecretkey ¶
func EncodeSecretkey(priv crypto.PrivateKey) ([]byte, error)
EncodeSecretkey serializes a secret key to the PEM format.
func GenerateKey ¶
func GenerateKey(algo x509.PublicKeyAlgorithm) (pubBytes []byte, privBytes []byte, err error)
GenerateKey generates a key pair given public key algorithm. Available algorithms are: RSA, ECDSA256, RSA.
func MarshalPKIXPublicKey ¶
MarshalPKIXPublicKey wraps x509.MarshalPublicKey and additionaly handles ED25519 public keys.
func NewECDSAKeyPair ¶
func NewECDSAKeyPair() (crypto.PublicKey, *ecdsa.PrivateKey, error)
NewECDSAKeyPair generates a new ECDSA key pair using the P-256 curve.
func NewEd25519KeyPair ¶
func NewEd25519KeyPair() (crypto.PublicKey, *ed25519.PrivateKey, error)
NewEd25519KeyPair generates a new ed25519 key pair.
func NewRSAKeyPair ¶
func NewRSAKeyPair() (crypto.PublicKey, *rsa.PrivateKey, error)
NewRSAKeyPair generates a new RSA key pair.
func ParseECDSAPKCS8Key ¶
ParseECDSAPKCS8Key decodes a PEM block containing an ASN1. DER encoded secret key of type ECDSA embedded in PKCS#8.
func ParsePKIXPublicKey ¶
ParsePKIXPublicKey parses a DER encoded public key. If of type ED25519 it parses the public key directly, if not it relies on x509 public key parser.
func ParsePublicKey ¶
ParsePublicKey parses a PEM encoded public Key If of type ED25519 it parses the public key directly, if not it relies on x509 public key parser.
func ParseRSAPKCS8Key ¶
ParseRSAPKCS8Key decodes a PEM block containing an ASN1. DER encoded private key of type RSA embedded in PKCS#8.
func ParseSecretKey ¶
ParseSecretKey deserializes a secret key from a PEM format.
func UnmarshalED25519Key ¶
UnmarshalED25519Key unmarshals an ASN1. DER encoded private key of type ED25519.
Types ¶
This section is empty.