Help us shape the future of Go! Take the 2026 Go Developer Survey

crypto

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeyTypeRSA represents the RSA type of keys
	KeyTypeRSA = "rsa"

	// KeySchemeRSASSAPSSSHA256 represents rsassa-pss-sha256 scheme
	KeySchemeRSASSAPSSSHA256 = "rsassa-pss-sha256"
)
View Source
const RSAKeyLength = 2048

RSAKeyLength define the length of RSA keys

Variables

View Source
var (
	// ErrorKeyUninitialized will be present when key is used before Deserialize called
	ErrorKeyUninitialized = errors.New("key not initialized, call Deserialize first")
	// ErrorDeserializeKey means the key format is not valid
	ErrorDeserializeKey = errors.New("error on deserialize key, check if the key is valid")
	// ErrorUnsupportedKeyType means we don't supported this type of key
	ErrorUnsupportedKeyType = errors.New("provided key type not supported")
	// ErrorUnsupportedKeySchema means we don't support this schema
	ErrorUnsupportedKeySchema = errors.New("provided schema not supported")
)

Functions

func NewKeyPair

func NewKeyPair(keyType, keyScheme string) (PubKey, PrivKey, error)

NewKeyPair return a pair of key

func RSAPair

func RSAPair() (*RSAPubKey, *RSAPrivKey, error)

RSAPair generate a pair of rsa keys

Types

type PrivKey

type PrivKey interface {
	Serializable
	// Type returns the type of the key, e.g. RSA
	Type() string
	// Scheme returns the scheme of  signature algorithm, e.g. rsassa-pss-sha256
	Scheme() string
	// Signature sign a signature with the key for payload
	Signature(payload []byte) (string, error)
	// Public returns public key of the PrivKey
	Public() PubKey
}

PrivKey is the private key that provide signature method

func NewPrivKey

func NewPrivKey(keyType, keyScheme string, key []byte) (PrivKey, error)

NewPrivKey return PrivKey

type PubKey

type PubKey interface {
	Serializable
	// Type returns the type of the key, e.g. RSA
	Type() string
	// Scheme returns the scheme of  signature algorithm, e.g. rsassa-pss-sha256
	Scheme() string
	// VerifySignature check the signature is right
	VerifySignature(payload []byte, sig string) error
}

PubKey is a public key available to TiUp

func NewPubKey

func NewPubKey(keyType, keyScheme string, key []byte) (PubKey, error)

NewPubKey return PrivKey

type RSAPrivKey

type RSAPrivKey struct {
	// contains filtered or unexported fields
}

RSAPrivKey represents the private key of RSA

func (*RSAPrivKey) Deserialize

func (k *RSAPrivKey) Deserialize(key []byte) error

Deserialize generate a private key from pem format

func (*RSAPrivKey) Public

func (k *RSAPrivKey) Public() PubKey

Public returns public key of the PrivKey

func (*RSAPrivKey) Scheme

func (k *RSAPrivKey) Scheme() string

Scheme returns the scheme of signature algorithm, e.g. rsassa-pss-sha256

func (*RSAPrivKey) Serialize

func (k *RSAPrivKey) Serialize() ([]byte, error)

Serialize generate the pem format for a key

func (*RSAPrivKey) Signature

func (k *RSAPrivKey) Signature(payload []byte) (string, error)

Signature sign a signature with the key for payload

func (*RSAPrivKey) Type

func (k *RSAPrivKey) Type() string

Type returns the type of the key, e.g. RSA

type RSAPubKey

type RSAPubKey struct {
	// contains filtered or unexported fields
}

RSAPubKey represents the public key of RSA

func (*RSAPubKey) Deserialize

func (k *RSAPubKey) Deserialize(key []byte) error

Deserialize generate a public key from pem format

func (*RSAPubKey) Scheme

func (k *RSAPubKey) Scheme() string

Scheme returns the scheme of signature algorithm, e.g. rsassa-pss-sha256

func (*RSAPubKey) Serialize

func (k *RSAPubKey) Serialize() ([]byte, error)

Serialize generate the pem format for a key

func (*RSAPubKey) Type

func (k *RSAPubKey) Type() string

Type returns the type of the key, e.g. RSA

func (*RSAPubKey) VerifySignature

func (k *RSAPubKey) VerifySignature(payload []byte, sig string) error

VerifySignature check the signature is right

type Serializable

type Serializable interface {
	// Translate the key to the format that can be stored
	Serialize() ([]byte, error)

	// Deserialize a key from data
	Deserialize([]byte) error
}

Serializable represents object that can be serialized and deserialized

Jump to

Keyboard shortcuts

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