NAME
TweetNacl - pulic key crypto lib
SYNOPSIS
# ----------------------------------------------------------------------
# public key encryption
# ----------------------------------------------------------------------
use Crypt::TweetNacl::PublicKey;
# create keys
my $alice = KeyPair.new;
my $bob = KeyPair.new;
# create Buf to encrypt
my $msg = 'Hello World'.encode('UTF-8');
# encrypt
my $cb = CryptoBox.new(pk => $alice.public , sk => $bob.secret);
my $data = $cb.encrypt($msg);
# decrypt
my $cbo = CryptoBoxOpen.new(pk => $bob.public , sk => $alice.secret);
my $rmsg = $cbo.decrypt($data);
say $rmsg.decode('UTF-8')
# ----------------------------------------------------------------------
# public key signatures
# ----------------------------------------------------------------------
use Crypt::TweetNacl::Sign;
# create key
my $keypair = KeyPair.new;
my $msg = 'Hello World'.encode('UTF-8');
# sign
my $cs = CryptoSign.new(buf => $msg, sk => $keypair.secret);
say $cs.signature
# verify, throws if message was corrupted
my $cso = CryptoSignOpen.new(buf => $cs.signature, pk => $keypair.public);
say $cso.message.decode('UTF-8') # 'Hello World'
# ----------------------------------------------------------------------
# secret key encryption
# ----------------------------------------------------------------------
use Crypt::TweetNacl::SecretKey;
# create key
my $alice = Key.new;
# create Buf to encrypt
my $msg = 'Hello World'.encode('UTF-8');
# encrypt
my $csb = CryptoSecretBox.new(sk => $alice.secret);
my $data = $csb.encrypt($msg);
# decrypt
my $csbo = CryptoSecretBoxOpen.new(sk => $alice.secret);
my $rmsg = $csbo.decrypt($data);
say $rmsg.decode('UTF-8') # 'Hello World'
INSTALL
# on debian like systems:
apt install rakudo moarvm-dev
git clone https://github.com/soundart/perl6-tweetnacl
cd perl6-tweetnacl
zef install .
DESCRIPTION
For details see
This is my first perl6 attempt. Feedback very much appreciated.
open questions:
- class Ciphertext: attributes $!data and $!nonce have to be
transported(e.g. send via network) from encryption to
decryption host. Should there be a serialize() method?
COPYRIGHT AND LICENSE
see LICENSE