rsa

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKeys

func GenerateKeys(bits int, opts ...KeyOption) (PrivateKey, PublicKey, error)

GenerateKeys generates a private key of bits and a public key.

func StorePrivateKey added in v0.5.2

func StorePrivateKey(file string, privateKey PrivateKey, opts ...KeyOption) error

StorePrivateKey stores the private key to the file.

func StorePublicKey added in v0.5.2

func StorePublicKey(file string, publicKey PublicKey, opts ...KeyOption) error

StorePublicKey stores the public key to the file.

func WritePrivateKey added in v0.5.2

func WritePrivateKey(writer io.Writer, privateKey PrivateKey, opts ...KeyOption) error

WritePrivateKey writes the private key to the writer.

func WritePublicKey added in v0.5.2

func WritePublicKey(writer io.Writer, publicKey PublicKey, opts ...KeyOption) error

WritePublicKey writes the public key to the writer.

Types

type Config

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

func (*Config) Apply added in v0.5.2

func (c *Config) Apply(opts ...Option) *Config

type KeyConfig

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

func (*KeyConfig) Apply added in v0.5.2

func (kc *KeyConfig) Apply(opts ...KeyOption) *KeyConfig

type KeyOption

type KeyOption func(conf *KeyConfig)

func WithKeyDecodePrivate added in v0.5.2

func WithKeyDecodePrivate(decode func(data []byte) (*rsa.PrivateKey, error)) KeyOption

WithKeyDecodePrivate sets decode to key config.

func WithKeyDecodePublic added in v0.5.2

func WithKeyDecodePublic(decode func(data []byte) (*rsa.PublicKey, error)) KeyOption

WithKeyDecodePublic sets decode to key config.

func WithKeyEncodePrivate added in v0.5.2

func WithKeyEncodePrivate(encode func(key *rsa.PrivateKey) ([]byte, error)) KeyOption

WithKeyEncodePrivate sets encode to key config.

func WithKeyEncodePublic added in v0.5.2

func WithKeyEncodePublic(encode func(key *rsa.PublicKey) ([]byte, error)) KeyOption

WithKeyEncodePublic sets encode to key config.

func WithKeyRandom added in v0.5.2

func WithKeyRandom(random io.Reader) KeyOption

WithKeyRandom sets random to key config.

type Option

type Option func(conf *Config)

func WithBase64 added in v0.5.2

func WithBase64() Option

WithBase64 sets base64 encoding to config.

func WithCryptoHash

func WithCryptoHash(hash crypto.Hash) Option

WithCryptoHash sets crypto hash to config.

func WithHash

func WithHash(hash hash.Hash) Option

WithHash sets hash to config.

func WithHex added in v0.5.2

func WithHex() Option

WithHex sets hex encoding to config.

func WithRandom

func WithRandom(random io.Reader) Option

WithRandom sets random to config.

func WithSalt added in v0.5.2

func WithSalt(saltLength int) Option

WithSalt sets salt length to config.

type PrivateKey

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

func LoadPrivateKey

func LoadPrivateKey(file string, opts ...KeyOption) (PrivateKey, error)

LoadPrivateKey loads the private key from the file.

func ReadPrivateKey

func ReadPrivateKey(reader io.Reader, opts ...KeyOption) (PrivateKey, error)

ReadPrivateKey reads the private key from the reader.

func (PrivateKey) DecryptOAEP

func (pk PrivateKey) DecryptOAEP(data []byte, label []byte, opts ...Option) ([]byte, error)

DecryptOAEP decrypts data with oaep.

func (PrivateKey) DecryptPKCS1v15

func (pk PrivateKey) DecryptPKCS1v15(data []byte, opts ...Option) ([]byte, error)

DecryptPKCS1v15 decrypts data with pkcs1 v15.

func (PrivateKey) DecryptPKCS1v15SessionKey

func (pk PrivateKey) DecryptPKCS1v15SessionKey(data []byte, sessionKey []byte, opts ...Option) error

DecryptPKCS1v15SessionKey decrypts data using a session key with pkcs1 v15.

func (PrivateKey) SignPKCS1v15

func (pk PrivateKey) SignPKCS1v15(hashed []byte, opts ...Option) ([]byte, error)

SignPKCS1v15 signs hashed with pkcs1 v15.

func (PrivateKey) SignPSS

func (pk PrivateKey) SignPSS(digest []byte, opts ...Option) ([]byte, error)

SignPSS signs digest with pss.

type PublicKey

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

func LoadPublicKey

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

LoadPublicKey loads the public key from the file.

func ReadPublicKey

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

ReadPublicKey reads the public key from the reader.

func (PublicKey) EncryptOAEP

func (pk PublicKey) EncryptOAEP(data []byte, label []byte, opts ...Option) ([]byte, error)

EncryptOAEP encrypts data with oaep.

func (PublicKey) EncryptPKCS1v15

func (pk PublicKey) EncryptPKCS1v15(data []byte, opts ...Option) ([]byte, error)

EncryptPKCS1v15 encrypts data with pkcs1 v15.

func (PublicKey) VerifyPKCS1v15

func (pk PublicKey) VerifyPKCS1v15(hashed []byte, sign []byte, opts ...Option) error

VerifyPKCS1v15 verifies hashed with pkcs1 v15.

func (PublicKey) VerifyPSS

func (pk PublicKey) VerifyPSS(digest []byte, sign []byte, opts ...Option) error

VerifyPSS verifies digest with pss.

Jump to

Keyboard shortcuts

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