rsa

package
v0.0.0-...-ad5b1a2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDecryption     = errors.New("rsa: decryption error")
	ErrMessageTooLong = errors.New("rsa: message too long for RSA public key size")
)

Functions

func MarshalPKCS1PrivateKey

func MarshalPKCS1PrivateKey(priv *PrivateKey) []byte

MarshalPKCS1PrivateKey marshals an RSA private key in PKCS #1, ASN.1 DER form.

func MarshalPKCS1PublicKey

func MarshalPKCS1PublicKey(pub *PublicKey) []byte

MarshalPKCS1PublicKey marshals an RSA public key in PKCS #1, ASN.1 DER form.

Types

type PrivateKey

type PrivateKey struct {
	PublicKey
	D      *big.Int   // private exponent
	Primes []*big.Int // prime factors of N, has >= 2 elements.
}

func GenerateKeypair

func GenerateKeypair(bits uint) (priv *PrivateKey)

GenerateKeypair generates an RSA keypair with two primes and the given size

func ParsePKCS1PrivateKey

func ParsePKCS1PrivateKey(der []byte) (*PrivateKey, error)

ParsePKCS1PrivateKey parses an RSA private key in PKCS #1, ASN.1 DER form.

func (*PrivateKey) DecryptOAEP

func (priv *PrivateKey) DecryptOAEP(ciphertext []byte, hash hash.Hash, label []byte) (plaintext []byte, err error)

DecryptOAEP decrypts plaintext with RSA using OAEP as a padding algorithm

func (*PrivateKey) DecryptUnpadded

func (priv *PrivateKey) DecryptUnpadded(ciphertext []byte) (plaintext []byte, err error)

DecryptUnpadded decrypts RSA ciphertext without any padding algorithm (textbook RSA). This is very insecure and you should never ever use this.

func (*PrivateKey) Public

func (priv *PrivateKey) Public() (pub *PublicKey)

Public returns the public part of the private key

type PublicKey

type PublicKey struct {
	N *big.Int // modulus
	E int64    // public exponent
}

func ParsePKCS1PublicKey

func ParsePKCS1PublicKey(der []byte) (*PublicKey, error)

ParsePKCS1PublicKey parses an RSA public key in PKCS #1, ASN.1 DER form.

func (*PublicKey) EncryptOAEP

func (pub *PublicKey) EncryptOAEP(plaintext []byte, hash hash.Hash, label []byte) (ciphertext []byte, err error)

EncryptOAEP encrypts plaintext with RSA using OAEP as a padding algorithm

func (*PublicKey) EncryptUnpadded

func (pub *PublicKey) EncryptUnpadded(plaintext []byte) (ciphertext []byte, err error)

EncryptUnpadded encrypts plaintext with RSA without any padding algorithm (textbook RSA). This is very insecure and you should never ever use this.

func (*PublicKey) Size

func (pub *PublicKey) Size() (size int)

Size returns the modulus size in bits

Jump to

Keyboard shortcuts

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