rsa

package
v0.0.0-...-b075d96 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncryptDefault

func EncryptDefault(plainData, publicKey []byte) (cipherData string, err error)

func GenerateKeyPair

func GenerateKeyPair() (privateKey, publicKey []byte, err error)

GenerateKeyPair is a function to generate new Private and Public key pair The function receive no input. The output is private and public key in []byte

The output is usable for immediate encryption. If need to store the keys, the efficient way is to use base64 format. It will work easily to store the keys in any kind of storage, including text file. Example:

privatKeyB64 := base64.StdEncoding.EncodeToString(privateKeyByte)

To make keys exportable; PEM format is the standart ways. Use *GenerateKeyPairInPEM* function.

func GenerateKeyPairInPEM

func GenerateKeyPairInPEM() (privateKey, publicKey []byte, privateKeyPem, publicKeyPem []byte, err error)

GenerateKeyPairInPEM is the extension of *GenerateKeyPair* to create key pair in PEM encoded. PEM is a de facto file format for storing and sending keys based on a set of 1993 IETF. The output is 2 pair;

  1. byte pair : for immediate usage and stored in internal system
  2. PEM encoded pair : for exporting the keys to other system

Most common use case for PEM encoded pair is either write to file using *ioutil.WriteFile* or send the data using HTTP/ API.

Types

type Client

type Client struct {
	PrivateKey *rsa.PrivateKey
	PublicKeys map[string]*rsa.PublicKey
}

func New

func New(privateKey []byte, publicKeys map[string][]byte) (client *Client, err error)

func (*Client) Decrypt

func (c *Client) Decrypt(cipherData []byte) (plainData []byte, err error)

func (*Client) DecryptFromBase64

func (c *Client) DecryptFromBase64(cipherData []byte) (plainData []byte, err error)

func (*Client) DecryptToString

func (c *Client) DecryptToString(cipherData []byte) (plainData string, err error)

func (*Client) Encrypt

func (c *Client) Encrypt(plainData []byte, target string) (cipherData []byte, err error)

func (*Client) EncryptToBase64

func (c *Client) EncryptToBase64(plainData []byte, target string) (cipherData string, err error)

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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