Giter VIP home page Giter VIP logo

encrypted_strings's Introduction

encrypted_strings

encrypted_strings provides dead-simple string encryption/decryption syntax.

Resources

API

Bugs

Development

Testing

Source

  • git://github.com/pluginaweek/encrypted_strings.git

Mailing List

Description

Encrypting and decrypting data is not exactly the most straightforward and DRY way. encrypted_strings improves the syntax and reduces the complexity, adding straightforward support for encrypting values using SHA-1, Symmetric, and Asymmetric ciphers.

Usage

SHA Encryption

>> password = 'shhhh'
=> "shhhh"
>> encrypted_password = password.encrypt
=> "66c85d26dadde7e1db27e15a0776c921e27143bd"
>> encrypted_password.class
=> String
>> encrypted_password.cipher
=> #<EncryptedStrings::ShaCipher:0x2b9238889460 @salt="salt">
>> encrypted_password == 'shhhh'
=> true
>> encrypted_password.decrypt
NotImplementedError: Decryption is not supported using a(n) EncryptedStrings::ShaCipher
        from ./script/../config/../config/../vendor/plugins/encrypted_strings/lib/encrypted_strings/cipher.rb:13:in `decrypt'
        from ./script/../config/../config/../vendor/plugins/encrypted_strings/lib/encrypted_strings/extensions/string.rb:52:in `decrypt'
        from (irb):40

When encrypt is called, it creates a cipher instance which is used for future encryption and decryption of the string. The default cipher uses SHA-1 encryption. For ciphers that do not support decryption, equality with other strings is tested by encrypting the other string and checking whether the resulting encrypted value is the same.

Symmetric Encryption

>> password = 'shhhh'
=> "shhhh"
>> crypted_password = password.encrypt(:symmetric, :password => 'secret_key')
=> "qSg8vOo6QfU=\n"
>> crypted_password.class
=> String
>> crypted_password == 'shhhh'
=> true
>> password = crypted_password.decrypt
=> "shhhh"

Asymmetric encryption

>> password = 'shhhh'
=> "shhhh"
>> crypted_password = password.encrypt(:asymmetric, :public_key_file => './public.key', :private_key_file => './private.key')
=> "NEwVzcikYUKfS8HTc9L9eg/dMxBCLZ/nFr7J1aQYjkl3I2MPUD0lmjr/saC6\nTJEPwOl60Ki24H8TUwnGtZy14A==\n"
>> crypted_password.class
=> String
>> crypted_password == 'shhhh'
=> true
>> password = crypted_password.decrypt
=> "shhhh"

Dependencies

None.

References

encrypted_strings's People

Contributors

obrie avatar alto avatar fsanggang avatar michael-sands avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

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.