sodium.cr/spec/cox/crypto_box/secret_key_spec.cr
Didactic Drunk a02c54f4a7 Breaking API changes:
SecretKey renamed to CryptoBox::SecretKey
  PublicKey renamed to CryptoBox::PublicKey
  KeyPair removed.  Use CryptoBox::SecretKey instead.

  Cox.encrypt was removed.  Use `secret_key.pair(...).encrypt`
  Cox.decrypt was removed.  Use `secret_key.pair(...).decrypt`
2019-06-28 04:32:16 -07:00

26 lines
712 B
Crystal

require "../../spec_helper"
describe Cox::CryptoBox::SecretKey do
it "easy encrypt/decrypt" do
data = "Hello World!"
# Alice is the sender
alice = Cox::CryptoBox::SecretKey.new
# Bob is the recipient
bob = Cox::CryptoBox::SecretKey.new
# Encrypt a message for Bob using his public key, signing it with Alice's
# secret key
pair = alice.pair bob.public_key
nonce, encrypted = pair.encrypt_easy data
# Decrypt the message using Bob's secret key, and verify its signature against
# Alice's public key
bob.pair alice.public_key do |pair|
decrypted = pair.decrypt_easy encrypted, nonce: nonce
String.new(decrypted).should eq(data)
end
end
end