keys

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2019 License: Apache-2.0 Imports: 13 Imported by: 14

Documentation

Index

Constants

View Source
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"
)
View Source
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"
)
View Source
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
)
View Source
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

View Source
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}
)
View Source
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

func EncodePublicKey(pub crypto.PublicKey) ([]byte, error)

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

func MarshalPKIXPublicKey(pub crypto.PublicKey) ([]byte, error)

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

func ParseECDSAPKCS8Key(sk []byte) (*ecdsa.PrivateKey, *ecdsa.PublicKey, error)

ParseECDSAPKCS8Key decodes a PEM block containing an ASN1. DER encoded secret key of type ECDSA embedded in PKCS#8.

func ParsePKIXPublicKey

func ParsePKIXPublicKey(pk []byte) (crypto.PublicKey, *pkix.AlgorithmIdentifier, error)

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

func ParsePublicKey(pk []byte) (crypto.PublicKey, *pkix.AlgorithmIdentifier, error)

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

func ParseRSAPKCS8Key(sk []byte) (*rsa.PrivateKey, *rsa.PublicKey, error)

ParseRSAPKCS8Key decodes a PEM block containing an ASN1. DER encoded private key of type RSA embedded in PKCS#8.

func ParseSecretKey

func ParseSecretKey(sk []byte) (priv crypto.PrivateKey, pub crypto.PublicKey, err error)

ParseSecretKey deserializes a secret key from a PEM format.

func UnmarshalED25519Key

func UnmarshalED25519Key(sk []byte) (*ed25519.PrivateKey, *ed25519.PublicKey, error)

UnmarshalED25519Key unmarshals an ASN1. DER encoded private key of type ED25519.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL