Giter Site home page Giter Site logo

encryptor-rsa's Introduction

encryptor-rsa

encryptor-rsa is a golang library. Using this library you can:

  • to encrypt/decrypt data via RSA OAEP encryption algorithm
  • to serialize/deserialize RSA OAEP keys in PEM format (with password protection).

This repository contains:

  • encryptor-rsa library itself
  • demonstration - it is console application, which demonstrates main ideas of this library.
  • cmd - it is console application, which allows to:
    • generate public/private keys (private key can be protected by password)
    • encrypt message with existing public key
    • decrypt message with existing private key

Also wiki page is available.

Usage example

Initialize encryptor

Initialization depends on how do you want to use RsaEncryptor. In case of you want to generate new public/private keys without password protection, you can use:

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

If you want to do the same, but protect your private key with a password (using AES 256 CBC encryption) during serialization, you can use:

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

In case you want to encrypt message with existing public key, or decrypt message with existing unencrypted private key, you can use:

func InitEmpty() (RsaEncryptor, error)

If you want to do the same, but use encrypted private key, you should use:

func InitEmptyWithPassword(password string) (RsaEncryptor, error)

Encrypt

To encrypt you can use following methods:

  1. func (e *RsaEncryptor) Encrypt(message string) (string, error)
  2. func (e *RsaEncryptor) EncryptBytes(plain []byte) ([]byte, error)

Decrypt

To decrypt you can use following methods:

  1. func (e *RsaEncryptor) Decrypt(plain string) (string, error)
  2. func (e *RsaEncryptor) DecryptBytes(plain []byte) ([]byte, error)

NOTICE: you can't decrypt message, if private key was encrypted but password for this private key was not specified

PEM Serialization

To get public key in PEM-encoded string, you can use following method:

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

To get private key in PEM-encoded string, you can use this method:

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

NOTICE: PEM-encoded string with private key will be protected by password ONLY if e.Password was already set for e instance

To set public key from PEM-encoded string to e instance, you can use following method:

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

To set private key from PEM-encoded string to e, you can use this method:

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

NOTICE: password-protected PEM-encoded string will be decrypted ONLY if e.Password was already set for e instance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.