Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
func ParsePKCS1PublicKey ¶
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 ¶
EncryptUnpadded encrypts plaintext with RSA without any padding algorithm (textbook RSA). This is very insecure and you should never ever use this.