TweetNaCl is a C-extension for Ruby built on top of the official TweetNacl distribution. It exposes the basic functions using Ruby objects.
For a detailed explanation of TweetNaCl, here's the research paper associated with it.
gem install tweetnacl
input = "<text to cipher>"
nonce = "<a 24-char string>"
pk, sk = TweetNaCl.crypto_box_keypair # This generates a pair of public and secret keys
cipher = TweetNaCl.crypto_box(input, nonce, pk, sk) # Encrypt !
output = TweetNaCl.crypto_box_open(cipher, nonce, pk, sk) # Decrypt!
assert_equal input, output # They're the same !
A KeyPair object represents a pair of public and secret keys. They are created
with the crypto_box_keypair
function call.
keypair = KeyPair.new
One can also create a keypair with an existing tuple of keys like this:
keypair = KeyPair.new(["<public_key>","<private_key>"])
A Cryptobox object contains all the methods required to sign, encrypt and verify messages. It is instantiated like so:
cb = CryptoBox.new(<Optional: KeyPair object>)
if no KeyPair is given, CryptoBox
will create a new one by calling KeyPair.new
Closing a box requires a message and a nonce.
cb = CryptBox.new(keypair_to_encrypt)
cb.close("hello world", "<a 24-byte nonce>")
Opening a box requires a closed box and a nonce.
[...]
closed_box = CryptBox.new(keypair_to_encrypt).tap do |b|
b.close("hello world", "<a 24-byte nonce>")
end
decryption_box = CryptBox.new(keypair_to_decrypt)
decryption_box.open(closed_box, "<a 24-byte nonce>")
Generate a pair of public and secret keys.
Encrypt and sign the input given the other parameters.
Decrypt and verify the signature of the ciphered message given the other parameters.
Encrypt the input given the other parameters.
Decrypt the ciphered message given the other parameters.
Generate a pair of public and secret keys.
Sign a message with a secret key.
Verify the signature in message with a public key.
- crypto_box (aliased crypto_box_curve25519xsalsa20poly1305)
- crypto_box_open (aliased crypto_box_curve25519xsalsa20poly1305_open)
- crypto_box_keypair
- crypto_box_beforenm
- crypto_box_afternm
- crypto_box_open_afternm
- crypto_core_salsa20
- crypto_core_hsalsa20
- crypto_hashblocks = crypto_hashblocks_sha512
- crypto_hash = crypto_hash_sha512
- crypto_onetimeauth = crypto_onetimeauth_poly1305
- crypto_onetimeauth_verify
- crypto_scalarmult = crypto_scalarmult_curve25519
- crypto_scalarmult_base
- crypto_secretbox (aliased crypto_secretbox_xsalsa20poly1305)
- crypto_secretbox_open (aliased crypto_secretbox_xsalsa20poly1305_open)
- crypto_sign = crypto_sign_ed25519
- crypto_sign_open
- crypto_sign_keypair
- crypto_stream = crypto_stream_xsalsa20
- crypto_stream_xor
- crypto_stream_salsa20
- crypto_stream_salsa20_xor
- crypto_verify_16
- crypto_verify_32
- USDT / probes
- CryptoBox object
- CryptoSign object
No. And it never will.
No. Until proven otherwise.
- Fork it ( https://github.com/franckverrot/tweetnacl/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Franck Verrot, Copyright 2014. See LICENSE.txt.