Documentation ¶
Index ¶
- func DecryptDefault(ciphertext string, privateKey []byte) (plainData []byte, err error)
- func EncryptDefault(plainData, publicKey []byte) (cipherData string, err error)
- func GenerateKeyPair() (privateKey, publicKey []byte, err error)
- func GenerateKeyPairInPEM() (privateKey, publicKey []byte, privateKeyPem, publicKeyPem []byte, err error)
- func SignDefault(plaintext, privateKey []byte) (signature string, err error)
- func VerifyDefault(plaintext, publicKey []byte, signature string) (err error)
- type Client
- func (c *Client) Decrypt(cipherData []byte) (plainData []byte, err error)
- func (c *Client) DecryptFromBase64(cipherdata string) (plainData []byte, err error)
- func (c *Client) DecryptToString(cipherData []byte) (plainData string, err error)
- func (c *Client) Encrypt(plainData []byte, target string) (cipherData []byte, err error)
- func (c *Client) EncryptToBase64(plainData []byte, target string) (cipherData string, err error)
- func (c *Client) Sign(plaintext []byte) (signature []byte, err error)
- func (c *Client) Verify(plaintext, signature []byte, target string) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecryptDefault ¶
func EncryptDefault ¶
func GenerateKeyPair ¶
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;
- byte pair : for immediate usage and stored in internal system
- 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.
func SignDefault ¶
func VerifyDefault ¶
Types ¶
type Client ¶
type Client struct { PrivateKey *rsa.PrivateKey PublicKeys map[string]*rsa.PublicKey }