rsa

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Primes is the prime of rsa key.
	// See rsa.GenerateMultiPrimeKey.
	Primes = 2
)
View Source
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.

func (KeyOption) ApplyTo

func (ko KeyOption) ApplyTo(cfg *KeyConfig)

ApplyTo applies key option to key config.

type Option

type Option func(cfg *Config)

Option is an option for config.

func WithCryptoHash

func WithCryptoHash(hash crypto.Hash) Option

WithCryptoHash sets crypto hash to cfg.

func WithHash

func WithHash(hash hash.Hash) Option

WithHash sets hash to cfg.

func WithRandom

func WithRandom(random io.Reader) Option

WithRandom sets random to cfg.

func (Option) ApplyTo

func (o Option) ApplyTo(cfg *Config)

ApplyTo applies option to config.

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) Bytes

func (pk PrivateKey) Bytes() cryptox.Bytes

Bytes returns the bytes of pk.

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

func (pk PrivateKey) DecryptPKCS1v15(msg cryptox.Bytes, opts ...Option) (cryptox.Bytes, error)

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) Key

func (pk PrivateKey) Key() *rsa.PrivateKey

Key returns the key of pk.

func (PrivateKey) SignPKCS1v15

func (pk PrivateKey) SignPKCS1v15(hashed cryptox.Bytes, opts ...Option) (cryptox.Bytes, error)

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

func LoadPublicKey(keyFile string, opts ...KeyOption) (PublicKey, error)

LoadPublicKey loads public key from a file.

func MustLoadPublicKey

func MustLoadPublicKey(keyFile string, opts ...KeyOption) PublicKey

MustLoadPublicKey loads public key from a file or panic on failed.

func ParsePublicKey

func ParsePublicKey(keyBytes cryptox.Bytes, opts ...KeyOption) (PublicKey, error)

ParsePublicKey parses public key from pem bytes.

func ReadPublicKey

func ReadPublicKey(keyReader io.Reader, opts ...KeyOption) (PublicKey, error)

ReadPublicKey reads public key from a reader.

func (PublicKey) Bytes

func (pk PublicKey) Bytes() cryptox.Bytes

Bytes returns the bytes of pk.

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

func (pk PublicKey) EncryptPKCS1v15(msg cryptox.Bytes, opts ...Option) (cryptox.Bytes, error)

EncryptPKCS1v15 encrypts msg with pkcs1 v15.

func (PublicKey) EqualsTo

func (pk PublicKey) EqualsTo(publicKey PublicKey) bool

EqualsTo returns if pk equals to privateKey.

func (PublicKey) Key

func (pk PublicKey) Key() *rsa.PublicKey

Key returns the key of pk.

func (PublicKey) String

func (pk PublicKey) String() string

String returns the formatted string of pk.

func (PublicKey) VerifyPKCS1v15

func (pk PublicKey) VerifyPKCS1v15(hashed cryptox.Bytes, signature cryptox.Bytes, opts ...Option) error

VerifyPKCS1v15 verifies signature with pkcs1 v15.

func (PublicKey) VerifyPSS

func (pk PublicKey) VerifyPSS(digest cryptox.Bytes, signature cryptox.Bytes, saltLength int, opts ...Option) error

VerifyPSS verifies signature with pss.

type PublicKeyDecoder

type PublicKeyDecoder func(keyPem cryptox.Bytes) (*rsa.PublicKey, error)

PublicKeyDecoder decodes public key from pem bytes.

func (PublicKeyDecoder) Decode

func (pke PublicKeyDecoder) Decode(keyPem cryptox.Bytes) (*rsa.PublicKey, error)

Decode decodes public key from pem bytes.

type PublicKeyEncoder

type PublicKeyEncoder func(key *rsa.PublicKey) (cryptox.Bytes, error)

PublicKeyEncoder encodes public key to pem bytes.

func (PublicKeyEncoder) Encode

func (pke PublicKeyEncoder) Encode(key *rsa.PublicKey) (cryptox.Bytes, error)

Encode encodes public key to pem bytes.

Jump to

Keyboard shortcuts

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