Documentation
¶
Overview ¶
Package crypto implements the ECDSA P256 SHA256 algorithm. Some day we might be brave enough to implement EdDSA Curve25519 signatures ( https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-02 ) but not today. The ECDSA implementation is largely based on the https://github.com/gtank/cryptopasta code. The reading and writing is mostly hacked together from the pem, elliptic, and ecdsa documentations, so these parts may not be entirely interoperable with other readers and writers.
Index ¶
Constants ¶
const ( // PrivateKeyPEMType is the type recorded in the pem preamble for our private keys PrivateKeyPEMType = "ECDSA P256 PRIVATE KEY" // PublicKeyPEMType is the type recorded in the pem preamble for our public keys PublicKeyPEMType = "ECDSA P256 PUBLIC KEY" // CurveNameHeader is the key for the Curve-Name pem header CurveNameHeader = "Curve-Name" // NameHeader is the key for the Name pem header NameHeader = "Name" // CommentHeader is the key for the Comment pem header CommentHeader = "Comment" // SignaturePEMType is the type recorder in the pem preamble for signaures SignaturePEMType = "ECDSA P256 SIGNATURE" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type PrivateKey ¶
type PrivateKey struct { *ecdsa.PrivateKey Name string Comment string }
PrivateKey embeds the ecdsa.PrivateKey type with an extra Name and Comment
func NewPrivateKey ¶
func NewPrivateKey() (*PrivateKey, error)
NewPrivateKey creates a random ECDSA P256 private key (which includes a public key)
func ReadPrivateKey ¶
func ReadPrivateKey(in io.Reader) (*PrivateKey, error)
ReadPrivateKey looks for the private and public key components of the ecdsa.PrivateKey in the Reader's bytes. If both are found, the pem blocks are decoded. The data is expected to have been written by the WritePrivateKey function.
func (*PrivateKey) GetPublicKey ¶
func (k *PrivateKey) GetPublicKey() *PublicKey
GetPublicKey returns the PublicKey from the PrivateKey. This should be used instead of pulling the PublicKey field directly out of the PrivateKey. That would pull an *ecdsa.PublicKey out, instead of a *crypto.PublicKey. I would liked to have just called this method PublicKey(), but that causes strange recursive function references, so we need to use GetPublicKey() instead.
func (*PrivateKey) Write ¶
func (k *PrivateKey) Write(out io.Writer) error
WritePrivateKey encodes the private key into the output Writer. The pem encoding is used, storing the private key D value in one block and the public key in a second. The public key is written using the WritePublicKey function. The pem headers include the curve name for future-proofing.
type PublicKey ¶
PublicKey embeds the ecdsa.PublicKey type with an extra Name and Comment
func ReadPublicKey ¶
ReadPublicKey looks for the public key components of the ecdsa.PublicKey in the Reader's bytes. The pem block is decoded. THe data is expected to have been written by the WritePublicKey or WritePrivateKey function.
func (*PublicKey) Write ¶
WritePublicKey encodes the public key to the output Writer. The pem encoding is used, storing the X and Y values encoded by the elliptic.Marshal function and the appropriate curve. The pem headers include the curve name for future-proofing. If you are writing a public key separately from a crypto.PrivateKey, use the privateKey.GetPublicKey() method instead of pulling PublicKey field directly from the privateKey.