On a completely unrelated topic, RbNaCl is also the empirical formula for Rubidium Sodium Chloride.
Need help with RbNaCl? Join the RbNaCl Google Group. We're also on IRC at #cryptosphere on irc.freenode.net
NaCl is a different kind of cryptographic library. In the past crypto libraries were kitchen sinks of little bits and pieces, like ciphers, MACs, signature algorithms, and hash functions. To accomplish anything you had to make a lot of decisions about which specific pieces to use, and if any of your decisions were wrong, the result was an insecure system. The choices are also not easy: EAX? GCM? CCM? AES-CTR? CMAC? OMAC1? AEAD? NIST? CBC? CFB? CTR? ECB? OMGWTFBBQ!
NaCl puts cryptography on Rails! Instead of making you choose which cryptographic primitives to use, NaCl provides convention over configuration in the form of expertly-assembled high-level cryptographic APIs that ensure not only the confidentiality of your data, but also detect tampering. These high-level, easy-to-use APIs are designed to be hard to attack by default in ways primitives exposed by libraries like OpenSSL are not.
This approach makes NaCl a lot closer to a system like GPG than it is to the cryptographic primitive APIs in a library like OpenSSL. In addition, NaCl also uses state-of-the-art encryption, including Curve25519 elliptic curves and the XSalsa20 stream cipher. This means with NaCl you not only get a system which is designed to be secure-by-default, you also get one which is extremely fast with comparatively small cryptographic keys.
For more information on NaCl's goals, see Dan Bernstein's presentation Blaming the Cryptographic User
Is it any good?
You can use RbNaCl anywhere you can get libsodium installed (see below). RbNaCl is continuously integration tested on the following Ruby VMs:
- MRI 2.0, 2.1, 2.2, 2.3
- JRuby 1.7, 9000
NOTE: Want to avoid the hassle of installing libsodium? Use the rbnacl-libsodium gem
To use RbNaCl, you will need to install libsodium:
At least version
1.0.0 is recommended.
For OS X users, libsodium is available via homebrew and can be installed with:
brew install libsodium
For FreeBSD users, libsodium is available both via pkgng and ports. To install a binary package:
pkg install libsodium
To install from ports on FreeBSD, use your favorite ports front end (e.g. portmaster or portupgrade), or use make as follows:
cd /usr/ports/security/libsodium; make install clean
Once you have libsodium installed, add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install rbnacl
Inside of your Ruby program do:
...to pull it in as a dependency.
RbNaCl's documentation can be found in the Wiki. The following features are supported:
- SimpleBox: easy-to-use public-key or secret-key encryption "on Rails"
- Secret-key Encryption: authenticated symmetric encryption using a single key shared among parties
- Public-key Encryption: securely send messages to a given public key which can only be decrypted by a secret key
- Digital Signatures: sign messages with a private key which can be verified by a public one
- Authenticators: create codes which can be used to check the authenticity of messages
- Hash Functions: compute a secure, fixed-length code from a message which does not reveal the contents of the message
Additional power-user features are available. Please see the Wiki for further information.
RDoc documentation is also available.
Reporting Security Problems
If you have discovered a bug in RbNaCl of a sensitive nature, i.e. one which can compromise the security of RbNaCl users, you can report it securely by sending a GPG encrypted message. Please use the following key:
The key fingerprint is (or should be):
9148 85A2 6242 1628 B6AA AB45 4CB9 B3D0 BACC 8B71
While NaCl has designed to be easier-than-usual to use for a crypto library, cryptography is an incredibly difficult subject and it's always helpful to know as much as you can about it before applying it to a particular use case. That said, the creator of NaCl, Dan Bernstein, has published a number of papers about NaCl. If you are interested in learning more about how NaCl works, it's recommended that you read them:
- Cryptography in NaCl
- Curve25519: new Diffie-Hellman speed records
- Ed25519: High-speed high-security signatures
For more information on libsodium, please check out the Introducing Sodium blog post
Have a general interest in cryptography? Check out the free course Coursera offers from Stanford University Professor Dan Boneh:
Is it "Military Grade™"?
Only if your military understands twisted Edwards curves
Is it "Bank Grade™"?
No, that means 3DES, which this library doesn't support, sorry
Does it have a lock with a checkmark?
Sure, here you go:
- Fork this repository on Github
- Make your changes and send a pull request
- If your changes look good, we'll merge 'em
Copyright (c) 2012-2016 Jonathan Stott, Tony Arcieri. Distributed under the MIT License. See LICENSE.txt for further details.