Class: TweetNaCl::CryptoBox

Inherits:
Object
  • Object
show all
Defined in:
lib/tweetnacl/crypto_box.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keypair = KeyPair.new) ⇒ CryptoBox

Returns a new instance of CryptoBox.



5
6
7
# File 'lib/tweetnacl/crypto_box.rb', line 5

def initialize(keypair = KeyPair.new)
  @keypair = keypair
end

Instance Attribute Details

#cipherObject (readonly)

Returns the value of attribute cipher.



3
4
5
# File 'lib/tweetnacl/crypto_box.rb', line 3

def cipher
  @cipher
end

#keypairObject (readonly)

Returns the value of attribute keypair.



3
4
5
# File 'lib/tweetnacl/crypto_box.rb', line 3

def keypair
  @keypair
end

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'lib/tweetnacl/crypto_box.rb', line 3

def message
  @message
end

Instance Method Details

#close(message, nonce) ⇒ Object



9
10
11
# File 'lib/tweetnacl/crypto_box.rb', line 9

def close(message, nonce)
  @cipher = TweetNaCl.crypto_box(message, nonce, @keypair.public_key, @keypair.secret_key)
end

#open(box, nonce) ⇒ Object



13
14
15
# File 'lib/tweetnacl/crypto_box.rb', line 13

def open(box, nonce)
  @message = TweetNaCl.crypto_box_open(box.cipher, nonce, @keypair.public_key, @keypair.secret_key)
end