All Projects → itay-grudev → encryption

itay-grudev / encryption

Licence: MIT license
A simple wrapper for the OpenSSL Cipher library for Ruby and Rails applications. Distributed as a Gem through Rubygems.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to encryption

openssl
A functions wrapping of OpenSSL library for symmetric and asymmetric encryption and decryption.
Stars: ✭ 199 (+610.71%)
Mutual labels:  openssl, rsa
Swcrypt
RSA public/private key generation, RSA, AES encryption/decryption, RSA sign/verify in Swift with CommonCrypto in iOS and OS X
Stars: ✭ 632 (+2157.14%)
Mutual labels:  openssl, rsa
RSA-via-OpenSSL-libeay32
Реализация шифрования/дешифрование строки алгоритмом RSA через библиотеку openssl на Delphi
Stars: ✭ 29 (+3.57%)
Mutual labels:  openssl, rsa
Openssl Nodejs
is a package which gives you a possibility to run every OpenSSL command 🔒 in Node.js in a handy way. Moreover, parameters like -in, -keyin, -config and etc can be replaced by a raw data (Buffor).
Stars: ✭ 25 (-10.71%)
Mutual labels:  openssl, rsa
littleca
littleca是一个基于BC的小型ca库,支持ecc,rsa,dsa,sm2的证书签发,加密解密,签名验签操作,支持国密加解密,证书签发
Stars: ✭ 44 (+57.14%)
Mutual labels:  openssl, rsa
Open Crypto
🔑 Hashing (BCrypt, SHA2, HMAC), encryption (AES), public-key (RSA), and random data generation.
Stars: ✭ 115 (+310.71%)
Mutual labels:  openssl, rsa
Self Signed Ssl
Generate self-signed TLS certificate using OpenSSL
Stars: ✭ 188 (+571.43%)
Mutual labels:  openssl
Openssl
TLS/SSL and crypto library
Stars: ✭ 17,157 (+61175%)
Mutual labels:  openssl
Openssl For Iphone
A script for compiling OpenSSL for iOS Devices (iPhone, iPad, iPod Touch, AppleTV, MacCatalyst)
Stars: ✭ 2,190 (+7721.43%)
Mutual labels:  openssl
Lhttps
Create https for local development environment or localhost.
Stars: ✭ 172 (+514.29%)
Mutual labels:  openssl
enigma
A fast, native, cryptographic engine for the web
Stars: ✭ 101 (+260.71%)
Mutual labels:  rsa
accumulator
Cryptographic accumulators in Rust.
Stars: ✭ 115 (+310.71%)
Mutual labels:  rsa
Lagrange
A Beautiful Gemini Client
Stars: ✭ 238 (+750%)
Mutual labels:  openssl
Lua Openssl
Openssl binding for Lua
Stars: ✭ 206 (+635.71%)
Mutual labels:  openssl
spki
A bash script wrapper for OpenSSL that generates and manages a simple PKI suitable for small deployments
Stars: ✭ 39 (+39.29%)
Mutual labels:  openssl
Openssl Osx Ca
Simple periodic task to sync OSX Keychain certs to Homebrew installed OpenSSL & LibreSSL
Stars: ✭ 185 (+560.71%)
Mutual labels:  openssl
cosign
Cooperative RSA signing
Stars: ✭ 25 (-10.71%)
Mutual labels:  rsa
Bluecryptor
Swift cross-platform crypto library using CommonCrypto/libcrypto
Stars: ✭ 171 (+510.71%)
Mutual labels:  openssl
Libuwsc
A Lightweight and fully asynchronous WebSocket client library based on libev
Stars: ✭ 237 (+746.43%)
Mutual labels:  openssl
crypto.js
base on crypto module
Stars: ✭ 13 (-53.57%)
Mutual labels:  rsa

This project is currently stable, but will no longer be maintained.

Encryption

Gem Version Code Climate Build Status

A simple to use wrapper of the Ruby OpenSSL Cipher library for Ruby and Rails applications. This gem provides an easy to use interface for symmetrical and asymmetrical encryption using RSA.

Documentation

Additional documentation and class reference can be found in the Wiki section of the repository.

Installation

Install the gem

gem install encryption

or add it to your Gemfile

gem 'encryption'

Symmetric encryption

Using the global instance of the Encryption class

A simple example of how this gem works:

Encryption.key = 'A very long encryption key'
data = 'secret data'
encrypted_str = Encryption.encrypt( data )
Encryption.decrypt( encrypted_str ) == data # true

Using your own instance of the Encryption class

If you need a separate instance with custom settings, different than the global Encryption instance, here is how you can do it:

encryptor = Encryption::Symmetric.new
encryptor.key = 'A very long encryption key'
data = 'secret data'
encrypted_str = encryptor.encrypt( data )
encryptor.decrypt( encrypted_str ) == data # true

Configuration

For symmetric encryption/decryption you need to set an encryption key. You can also optionally set an initialization vector and a cipher.

Encryption.key - Your encryption key
Encryption.iv # Optional - Encryption initialization vector. Defaults to the character "\0" (Optional)
Encryption.cipher # Optional - Your encryption algorithm. Defaults to aes-256-cbc (Optional)

Running openssl list-cipher-commands in the terminal or calling OpenSSL::Cipher.ciphers in Ruby, which list all available ciphers.

You can configure both the global instance and a other instances with a block like this:

Encryption.config do |e|
    e.key = 'Don't look!'
    e.iv = 'This is probably the easiest way to use OpenSSL in Ruby'
    e.cipher = 'camellia-128-ecb' # if you're feeling adventurous
end

Asymmetric encryption (public/private key encryption)

The encryption gem also provides a DSL for asymmetric encryption.

Generating keypair

keypair = Encryption::Keypair.new # Accepts two optional arguments: size = 2048, password = nil
keypair.public_key # Instance of Encryption::PublicKey
keypair.private_key # Instance of Encryption::PrivateKey
# Or you can use this shorter version
public_key, private_key = Encryption::Keypair.generate( 2048 )

# You can dump keys to string
private_key.to_s

# or export them to PEM format
private_key.to_pem

# and optionally encrypt them with a passphrase
private_key.to_pem( 'passphrase' )

Encryption::PublicKey and Encryption::PrivateKey

Both classes have the same methods:

# Import an existing key
Encryption::PrivateKey.new( filename[, password] ) # Import from file
Encryption::PrivateKey.new( string[, password] ) # Import from string

# Encrypt / Decrypt data
public_key = Encryption::PublicKey.new( 'existing key' )
public_key.encrypt( 'some secret data' )
public_key.decrypt( "some encrypted data" )

Note: You can use both the public and the private key to encrypt or decrypt data.

Helpers

String helper

The gem adds the encrypt and decrypt methods to the String performing symmetric encryption. You can use them as follows:

# With the global Encryption instance
'Hello'.encrypt
'Hello'.encrypt!
'h3LL0'.decrypt
'h3LL0'.decrypt!

# With custom settings (and custom encryptor instance)
'secret'.encrypt( key: 'encryption key', iv: 'initialization vector', cipher: 'encryption cipher', encode: true )
# Note the encode option which will result in a base64 encoded string

'encrypted data'.decrypt( encoded: true ) # Will decrypt a base64 encoded string

# Or with a custom encryptor
encryptor = Encryption::Symmetric.new
encryptor.key = 'encryption key'
'secret data'.encrypt( encryptor: encryptor )

License

This gem is distributed under The MIT License.

Author

Itay Grudev <itay(at)grudev...com>

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].