rsa

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(priv *rsa.PrivateKey, msg []byte, opts ...Option) ([]byte, error)

Decrypt RSA

default Padding Pkcs1 support none padding (unsafe)

func Encrypt

func Encrypt(pub *rsa.PublicKey, msg []byte, opts ...Option) ([]byte, error)

Encrypt RSA

default Padding Pkcs1 support none padding (unsafe)

func PrivateKey

func PrivateKey(key string) (priv *rsa.PrivateKey)

PrivateKey parse a private key from a string

a string without the word BEGIN END

a string with the word BEGIN END

func Publickey

func Publickey(key string) (pub *rsa.PublicKey)

Publickey parse the public key from a string

a string without the word BEGIN END

a string with the word BEGIN END

Types

type Cipher

type Cipher struct {
	Error error
	// contains filtered or unexported fields
}

func New

func New(pub *rsa.PublicKey, priv *rsa.PrivateKey, opts ...Option) *Cipher

New RSA

New().String(gcrypto.Base64) => base64 string
New().Encrypt().String(gcrypto.Raw) => utf8 string
New().Decrypt().Bytes() => []byte
New().Release() => free Cipher to global rsapool

support none padding (unsafe)

func (*Cipher) Bytes

func (s *Cipher) Bytes() []byte

func (*Cipher) Decrypt

func (s *Cipher) Decrypt(msg []byte) *Cipher

func (*Cipher) DecryptPublic

func (s *Cipher) DecryptPublic(msg []byte) *Cipher

func (*Cipher) Encrypt

func (s *Cipher) Encrypt(msg []byte) *Cipher

func (*Cipher) EncryptPrivate

func (s *Cipher) EncryptPrivate(msg []byte) *Cipher

func (*Cipher) Sign

func (s *Cipher) Sign(msg []byte) (buf []byte, e error)

func (*Cipher) String

func (s *Cipher) String(enc func([]byte) string) (ss string)

func (*Cipher) Verify

func (s *Cipher) Verify(signed, msg []byte) (e error)

type Option

type Option func(*option)

func WithHash

func WithHash(hash crypto.Hash) Option

func WithPadding

func WithPadding(padding Padding) Option

type Padding

type Padding uint8
const (
	Pkcs1 Padding = iota
	OEAP
	None
)

Jump to

Keyboard shortcuts

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