GithubHelp home page GithubHelp logo

cyberflamego / cloak Goto Github PK

View Code? Open in Web Editor NEW

This project forked from danielberkompas/cloak

0.0 2.0 0.0 364 KB

Elixir encryption library designed for Ecto

License: MIT License

Shell 0.93% Ruby 1.29% Elixir 97.78%

cloak's Introduction

Cloak

Hex Version Build Status Inline docs Coverage Status

Cloak is an Elixir encryption library that implements several best practices and conveniences for Elixir developers:

  • Random IVs
  • Tagged ciphertexts
  • Elixir-native configuration

Documentation

Examples

Encrypt / Decrypt

{:ok, ciphertext} = MyApp.Vault.encrypt("plaintext")
# => {:ok, <<1, 10, 65, 69, 83, 46, 71, 67, 77, 46, 86, 49, 45, 1, 250, 221,
# =>  189, 64, 26, 214, 26, 147, 171, 101, 181, 158, 224, 117, 10, 254, 140, 207, 
# =>  215, 98, 208, 208, 174, 162, 33, 197, 179, 56, 236, 71, 81, 67, 85, 229, 
# =>  ...>>}

MyApp.Vault.decrypt(ciphertext)
# => {:ok, "plaintext"}

Reencrypt With New Algorithm/Key

"plaintext"
|> MyApp.Vault.encrypt!(:aes_256)
|> MyApp.Vault.decrypt!()
|> MyApp.Vault.encrypt!(:aes_256)
|> MyApp.Vault.decrypt!()
# => "plaintext"

Configuration

config :my_app, MyApp.Vault,
  ciphers: [
    # In AES.GCM, it is important to specify 12-byte IV length for
    # interoperability with other encryption software. See this GitHub issue
    # for more details: https://github.com/danielberkompas/cloak/issues/93
    # 
    # In Cloak 2.0, this will be the default iv length for AES.GCM.
    aes_gcm: {Cloak.Ciphers.AES.GCM, tag: "AES.GCM.V1", key: <<...>>, iv_length: 12},
    aes_ctr: {Cloak.Ciphers.AES.CTR, tag: "AES.CTR.V1", key: <<...>>}
  ]

Features

Random Initialization Vectors (IV)

Every strong encryption algorithm recommends unique initialization vectors. Cloak automatically generates unique vectors using :crypto.strong_rand_bytes, and includes the IV in the ciphertext. This greatly simplifies storage and is not a security risk.

Tagged Ciphertext

Each ciphertext contains metadata about the algorithm and key which was used to encrypt it. This allows Cloak to automatically select the correct key and algorithm to use for decryption for any given ciphertext.

This makes key rotation much easier, because you can easily tell whether any given ciphertext is using the old key or the new key.

Elixir-Native Configuration

Cloak works through Vault modules which you define in your app, and add to your supervision tree.

You can have as many vaults as you wish running simultaneously in your project. (This works well with umbrella apps, or any runtime environment where you have multiple OTP apps using Cloak)

Ecto Support

You can use Cloak to transparently encrypt Ecto fields, using cloak_ecto.

Security Notes

  • Cloak is built on Erlang's crypto library, and therefore inherits its security.
  • You can implement your own cipher modules to use with Cloak, which may use any other encryption algorithms of your choice.

cloak's People

Contributors

asummers avatar boydm avatar chulkilee avatar connorlay avatar danielberkompas avatar jc00ke avatar kevin-j-m avatar kgautreaux avatar mhussa avatar michaelherold avatar mikeastock avatar mjquinlan2000 avatar mspanc avatar philss avatar rrrene avatar ruan-brandao avatar tielur avatar tizpuppi avatar tomciopp avatar

Watchers

 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.