rsa

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(pk *rsa.PrivateKey, cipherText string, label string) (string, error)

Decrypt returns a decrypted text using RSA-OAEP algorithm.

Example:

// example data
cipherText := "..."
label := "some label"

// load the private key
privateKeyPem := `-----BEGIN RSA PRIVATE KEY-----...-----END RSA PRIVATE KEY-----`
privateKey, _ := rsa.PrivateKeyFromPEM([]byte(privateKeyPem))

// decrypt the cipher text
clearText, _ := rsa.Decrypt(privateKey, cipherText, label)

func Encrypt

func Encrypt(pk *rsa.PublicKey, clearText string, label string) (string, error)

Encrypt returns a cipher text of the clear text using RSA-OAEP algorithm.

Example:

// example data
clearText := "hello world"
label := "some label"

// load the private key
publicKeyPem := `-----BEGIN RSA PUBLIC KEY-----...-----END RSA PUBLIC KEY-----`
publicKey, _ := rsa.PublicKeyFromPEM([]byte(publicKeyPEM))

// encrypt the clear text
cipherText, _ := rsa.Encrypt(publicKey, clearText, label)

func GenerateKey

func GenerateKey(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error)

GenerateKey generates an RSA keypair of the given bit size.

func PrivateKeyFromBytes

func PrivateKeyFromBytes(priv []byte) (*rsa.PrivateKey, error)

PrivateKeyFromBytes bytes to private key

func PrivateKeyToBytes

func PrivateKeyToBytes(priv *rsa.PrivateKey) []byte

PrivateKeyToBytes private key to bytes

func PublicKeyFromBytes

func PublicKeyFromBytes(pub []byte) (*rsa.PublicKey, error)

PublicKeyFromBytes bytes to public key

func PublicKeyToBytes

func PublicKeyToBytes(pub *rsa.PublicKey) ([]byte, error)

PublicKeyToBytes public key to bytes

func Sign

func Sign(pk *rsa.PrivateKey, message string) (string, error)

Sign returns a message signature.

func ValidateSign

func ValidateSign(pk *rsa.PublicKey, message string, sign string) error

ValidateSignRsa validates the message signature.

Types

This section is empty.

Jump to

Keyboard shortcuts

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