Documentation
¶
Index ¶
- Variables
- func GenerateKeys(bits int, opts ...KeyOption) (PrivateKey, PublicKey, error)
- type Config
- type KeyConfig
- type KeyOption
- type Option
- type PrivateKey
- func GeneratePrivateKey(bits int, opts ...KeyOption) (PrivateKey, error)
- func LoadPrivateKey(keyFile string, opts ...KeyOption) (PrivateKey, error)
- func MustLoadPrivateKey(keyFile string, opts ...KeyOption) PrivateKey
- func ParsePrivateKey(keyBytes cryptox.Bytes, opts ...KeyOption) (PrivateKey, error)
- func ReadPrivateKey(keyReader io.Reader, opts ...KeyOption) (PrivateKey, error)
- func (pk PrivateKey) Bytes() cryptox.Bytes
- func (pk PrivateKey) DecryptOAEP(msg cryptox.Bytes, label cryptox.Bytes, opts ...Option) (cryptox.Bytes, error)
- func (pk PrivateKey) DecryptPKCS1v15(msg cryptox.Bytes, opts ...Option) (cryptox.Bytes, error)
- func (pk PrivateKey) DecryptPKCS1v15SessionKey(msg cryptox.Bytes, sessionKey cryptox.Bytes, opts ...Option) error
- func (pk PrivateKey) EqualsTo(privateKey PrivateKey) bool
- func (pk PrivateKey) Key() *rsa.PrivateKey
- func (pk PrivateKey) SignPKCS1v15(hashed cryptox.Bytes, opts ...Option) (cryptox.Bytes, error)
- func (pk PrivateKey) SignPSS(digest cryptox.Bytes, saltLength int, opts ...Option) (cryptox.Bytes, error)
- func (pk PrivateKey) String() string
- type PrivateKeyDecoder
- type PrivateKeyEncoder
- type PublicKey
- func GeneratePublicKey(privateKey PrivateKey, opts ...KeyOption) (PublicKey, error)
- func LoadPublicKey(keyFile string, opts ...KeyOption) (PublicKey, error)
- func MustLoadPublicKey(keyFile string, opts ...KeyOption) PublicKey
- func ParsePublicKey(keyBytes cryptox.Bytes, opts ...KeyOption) (PublicKey, error)
- func ReadPublicKey(keyReader io.Reader, opts ...KeyOption) (PublicKey, error)
- func (pk PublicKey) Bytes() cryptox.Bytes
- func (pk PublicKey) EncryptOAEP(msg cryptox.Bytes, label cryptox.Bytes, opts ...Option) (cryptox.Bytes, error)
- func (pk PublicKey) EncryptPKCS1v15(msg cryptox.Bytes, opts ...Option) (cryptox.Bytes, error)
- func (pk PublicKey) EqualsTo(publicKey PublicKey) bool
- func (pk PublicKey) Key() *rsa.PublicKey
- func (pk PublicKey) String() string
- func (pk PublicKey) VerifyPKCS1v15(hashed cryptox.Bytes, signature cryptox.Bytes, opts ...Option) error
- func (pk PublicKey) VerifyPSS(digest cryptox.Bytes, signature cryptox.Bytes, saltLength int, opts ...Option) error
- type PublicKeyDecoder
- type PublicKeyEncoder
Constants ¶
This section is empty.
Variables ¶
var ( // Primes is the prime of rsa key. // See rsa.GenerateMultiPrimeKey. Primes = 2 )
var (
// X509 is a x509Pem instance with X509 methods.
X509 = x509Pem{}
)
Functions ¶
func GenerateKeys ¶
func GenerateKeys(bits int, opts ...KeyOption) (PrivateKey, PublicKey, error)
GenerateKeys generates a key set of bits.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config stores all configurations used by encrypting/decrypting/signing/verifying.
type KeyConfig ¶
type KeyConfig struct {
// contains filtered or unexported fields
}
KeyConfig stores all configurations of key.
type KeyOption ¶
type KeyOption func(cfg *KeyConfig)
KeyOption is an option for key config.
func WithPrivateKeyDecoder ¶
func WithPrivateKeyDecoder(decoder PrivateKeyDecoder) KeyOption
WithPrivateKeyDecoder sets private key decoder to cfg.
func WithPrivateKeyEncoder ¶
func WithPrivateKeyEncoder(encoder PrivateKeyEncoder) KeyOption
WithPrivateKeyEncoder sets private key encoder to cfg.
func WithPublicKeyDecoder ¶
func WithPublicKeyDecoder(decoder PublicKeyDecoder) KeyOption
WithPublicKeyDecoder sets public key decoder to cfg.
func WithPublicKeyEncoder ¶
func WithPublicKeyEncoder(encoder PublicKeyEncoder) KeyOption
WithPublicKeyEncoder sets public key encoder to cfg.
type Option ¶
type Option func(cfg *Config)
Option is an option for config.
func WithCryptoHash ¶
WithCryptoHash sets crypto hash to cfg.
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
PrivateKey is the private key of rsa.
func GeneratePrivateKey ¶
func GeneratePrivateKey(bits int, opts ...KeyOption) (PrivateKey, error)
GeneratePrivateKey generates a private key of bits.
func LoadPrivateKey ¶
func LoadPrivateKey(keyFile string, opts ...KeyOption) (PrivateKey, error)
LoadPrivateKey loads private key from a file.
func MustLoadPrivateKey ¶
func MustLoadPrivateKey(keyFile string, opts ...KeyOption) PrivateKey
MustLoadPrivateKey loads private key from a file or panic on failed.
func ParsePrivateKey ¶
func ParsePrivateKey(keyBytes cryptox.Bytes, opts ...KeyOption) (PrivateKey, error)
ParsePrivateKey parses private key from pem bytes.
func ReadPrivateKey ¶
func ReadPrivateKey(keyReader io.Reader, opts ...KeyOption) (PrivateKey, error)
ReadPrivateKey reads private key from a reader.
func (PrivateKey) DecryptOAEP ¶
func (pk PrivateKey) DecryptOAEP(msg cryptox.Bytes, label cryptox.Bytes, opts ...Option) (cryptox.Bytes, error)
DecryptOAEP decrypts msg with oaep.
func (PrivateKey) DecryptPKCS1v15 ¶
DecryptPKCS1v15 decrypts msg with pkcs1 v15.
func (PrivateKey) DecryptPKCS1v15SessionKey ¶
func (pk PrivateKey) DecryptPKCS1v15SessionKey(msg cryptox.Bytes, sessionKey cryptox.Bytes, opts ...Option) error
DecryptPKCS1v15SessionKey decrypts msg using a session key with pkcs1 v15.
func (PrivateKey) EqualsTo ¶
func (pk PrivateKey) EqualsTo(privateKey PrivateKey) bool
EqualsTo returns if pk equals to privateKey.
func (PrivateKey) SignPKCS1v15 ¶
SignPKCS1v15 signs hashed data with pkcs1 v15.
func (PrivateKey) SignPSS ¶
func (pk PrivateKey) SignPSS(digest cryptox.Bytes, saltLength int, opts ...Option) (cryptox.Bytes, error)
SignPSS signs digest data with pss.
func (PrivateKey) String ¶
func (pk PrivateKey) String() string
String returns the formatted string of pk.
type PrivateKeyDecoder ¶
type PrivateKeyDecoder func(keyPem cryptox.Bytes) (*rsa.PrivateKey, error)
PrivateKeyDecoder decodes private key from pem bytes.
func (PrivateKeyDecoder) Decode ¶
func (pke PrivateKeyDecoder) Decode(keyPem cryptox.Bytes) (*rsa.PrivateKey, error)
Decode decodes private key from pem bytes.
type PrivateKeyEncoder ¶
type PrivateKeyEncoder func(key *rsa.PrivateKey) (cryptox.Bytes, error)
PrivateKeyEncoder encodes private key to pem bytes.
func (PrivateKeyEncoder) Encode ¶
func (pke PrivateKeyEncoder) Encode(key *rsa.PrivateKey) (cryptox.Bytes, error)
Encode encodes private key to pem bytes.
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey is the public key of rsa.
func GeneratePublicKey ¶
func GeneratePublicKey(privateKey PrivateKey, opts ...KeyOption) (PublicKey, error)
GeneratePublicKey generates a public key from private key.
func LoadPublicKey ¶
LoadPublicKey loads public key from a file.
func MustLoadPublicKey ¶
MustLoadPublicKey loads public key from a file or panic on failed.
func ParsePublicKey ¶
ParsePublicKey parses public key from pem bytes.
func ReadPublicKey ¶
ReadPublicKey reads public key from a reader.
func (PublicKey) EncryptOAEP ¶
func (pk PublicKey) EncryptOAEP(msg cryptox.Bytes, label cryptox.Bytes, opts ...Option) (cryptox.Bytes, error)
EncryptOAEP encrypts msg with oaep.
func (PublicKey) EncryptPKCS1v15 ¶
EncryptPKCS1v15 encrypts msg with pkcs1 v15.
type PublicKeyDecoder ¶
PublicKeyDecoder decodes public key from pem bytes.