Skip to content
Vitalii edited this page Jun 24, 2018 · 1 revision

encryptor_rsa

import "github.com/mrvine/encryptor-rsa"

rsa.go serialization-pem.go utils.go

const (
    DefaultKeyLength = 2048
)
func GetKeyLengthString() string

GetKeyLengthString allows to get string with available key lengths.

func GetKeyLengths() []int

GetKeyLength allows to get slice with available key lengths.

func IsValidKeyLength(keyLength int) bool

IsValidKeyLength allows to check if specified key length is a valid key length for current version of library.

type RsaEncryptor struct {
    PrivateKey rsa.PrivateKey
    PublicKey  rsa.PublicKey
    Password   string
}

RsaEncryptor allows to easily use RSA encryption algorithm

func Init() (e RsaEncryptor, err error)

Init initializes RsaEncryptor with default key length, empty password and just generated public/private keys.

func InitEmpty() RsaEncryptor

InitWithPassword initializes RsaEncryptor with nothing

func InitEmptyWithPassword(password string) RsaEncryptor

InitEmptyWithPassword initializes RsaEncryptor only with specified password (without keys generation).

func InitWithKeyLength(keyLength int) (e RsaEncryptor, err error)

InitWithKeyLength initializes RsaEncryptor with specified key length, empty password and just generated public/private keys.

func InitWithPassword(keyLength int, password string) (e RsaEncryptor, err error)

InitWithPassword initializes RsaEncryptor with specified key length, specified password and just generated public/private keys.

func (*RsaEncryptor) Decrypt

func (e *RsaEncryptor) Decrypt(encryptedData string) (string, error)

Decrypt allows to decrypt plain string using current private key. If private key is not set - error will be produced. If private key was encrypted, but password is not set - error will be produced.

func (*RsaEncryptor) DecryptBytes

func (e *RsaEncryptor) DecryptBytes(encrypted []byte) ([]byte, error)

DecryptBytes allows to decrypt plain string using current private key. If private key is not set - error will be produced. If private key was encrypted, but password is not set - error will be produced.

func (*RsaEncryptor) Encrypt

func (e *RsaEncryptor) Encrypt(plain string) (string, error)

Encrypt allows to encrypt plain string using current public key. If public key is not set - error will be produced.

func (*RsaEncryptor) EncryptBytes

func (e *RsaEncryptor) EncryptBytes(plain []byte) ([]byte, error)

EncryptBytes allows to encrypt plain bytes using current public key. If public key is not set - error will be produced.

func (*RsaEncryptor) GetPrivateKeyAsPem

func (e *RsaEncryptor) GetPrivateKeyAsPem() (p string, err error)

GetPrivateKeyAsPem allows to get private key in PEM-encoded string. If e.Password is not empty - private key will be encrypted via AES 256 CBC encryption algorithm, where key is e.Password.

func (*RsaEncryptor) GetPublicKeyAsPem

func (e *RsaEncryptor) GetPublicKeyAsPem() (string, error)

GetPublicKeyAsPem allows to get public key in PEM-encoded string

func (*RsaEncryptor) SavePrivateKeyInPem

func (e *RsaEncryptor) SavePrivateKeyInPem(filePath string) error

SavePrivateKeyInPem allows to save current private key to file.

func (*RsaEncryptor) SavePublicKeyInPem

func (e *RsaEncryptor) SavePublicKeyInPem(filePath string) error

SavePublicKeyInPem allows to save current public key to file.

func (*RsaEncryptor) SetPrivateKeyFromPem

func (e *RsaEncryptor) SetPrivateKeyFromPem(privateKeyString string) (err error)

SetPrivateKeyFromPem allows to set private key to current instance of RsaEncryptor from PEM-encoded string. If private key was encrypted - this method will try to decrypt via password from e.Password field.

func (*RsaEncryptor) SetPublicKeyFromPem

func (e *RsaEncryptor) SetPublicKeyFromPem(publicKeyString string) error

SetPublicKeyFromPem allows to set public key to current instance of RsaEncryptor from PEM-encoded string.


Generated by godoc2md