Class: Encrypto::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/encrypto/box.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nacl_box) ⇒ Box

Returns a new instance of Box.



4
5
6
# File 'lib/encrypto/box.rb', line 4

def initialize(nacl_box)
  @nacl_box = nacl_box
end

Class Method Details

.from_keypair(public_key, private_key) ⇒ Object



25
26
27
# File 'lib/encrypto/box.rb', line 25

def self.from_keypair(public_key, private_key)
  new(RbNaCl::SimpleBox.from_keypair(public_key, private_key))
end

.from_passphrase(passphrase) ⇒ Object



16
17
18
19
# File 'lib/encrypto/box.rb', line 16

def self.from_passphrase(passphrase)
  passphrase_sha = RbNaCl::Hash.sha256(passphrase)
  from_secret_key(passphrase_sha)
end

.from_secret_key(secret_key) ⇒ Object



21
22
23
# File 'lib/encrypto/box.rb', line 21

def self.from_secret_key(secret_key)
  new(RbNaCl::SimpleBox.from_secret_key(secret_key.b))
end

Instance Method Details

#box(value) ⇒ Object



8
9
10
# File 'lib/encrypto/box.rb', line 8

def box(value)
  @nacl_box.box(value)
end

#open(cipher_text) ⇒ Object



12
13
14
# File 'lib/encrypto/box.rb', line 12

def open(cipher_text)
  @nacl_box.open(cipher_text)
end