A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://rubydoc.info/github/cryptosphere/rbnacl/RbNaCl/Boxes/Sealed below:

Sealed – Documentation for cryptosphere/rbnacl (main) – RubyDoc.info

Class: RbNaCl::Boxes::Sealed
Inherits:
Object show all
Extended by:
Sodium
Defined in:
lib/rbnacl/boxes/sealed.rb
Overview

Sealed boxes are designed to anonymously send messages to a recipient given its public key.

Only the recipient can decrypt these messages, using its private key. While the recipient can verify the integrity of the message, it cannot verify the identity of the sender.

A message is encrypted using an ephemeral key pair, whose secret part is destroyed right after the encryption process.

Without knowing the secret key used for a given message, the sender cannot decrypt its own message later. And without additional data, a message cannot be correlated with the identity of its sender.

Class Method Summary collapse Instance Method Summary collapse Methods included from Sodium

sodium_constant, sodium_function, sodium_function_with_return_code, sodium_primitive, sodium_type

Constructor Details #initialize(public_key, private_key = nil) ⇒ RbNaCl::SealedBox

WARNING: you should strongly prefer the from_private_key/from_public_key class methods.

Create a new Sealed Box

Sets up the Box for deriving the shared key and encrypting and decrypting messages.

47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rbnacl/boxes/sealed.rb', line 47

def initialize(public_key, private_key = nil)
  unless private_key.nil?
    @private_key = private_key.is_a?(PrivateKey) ? private_key : PrivateKey.new(private_key)
    raise IncorrectPrimitiveError unless @private_key.primitive == primitive

    public_key = @private_key.public_key if public_key.nil?
  end

  @public_key = public_key.is_a?(PublicKey) ? public_key : PublicKey.new(public_key)
  raise IncorrectPrimitiveError unless @public_key.primitive == primitive
end
Class Method Details .from_private_key(private_key) ⇒ RbNaCl::SealedBox

Create a new Sealed Box for decrypting

Sets up the Box for decryption of new messages.

68
69
70
# File 'lib/rbnacl/boxes/sealed.rb', line 68

def self.from_private_key(private_key)
  new(nil, private_key)
end
.from_public_key(public_key) ⇒ RbNaCl::SealedBox

Create a new Sealed Box for encrypting

Sets up the Box for encryption of new messages.

81
82
83
# File 'lib/rbnacl/boxes/sealed.rb', line 81

def self.from_public_key(public_key)
  new(public_key, nil)
end
Instance Method Details #box(message) ⇒ String Also known as: encrypt
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/rbnacl/boxes/sealed.rb', line 92

def box(message)
    msg = message     ct  = Util.zeros(msg.bytesize + SEALBYTES)

  success = self.class.box_seal(ct, msg, msg.bytesize, @public_key.to_s)
  raise CryptoError, "Encryption failed" unless success

  ct
end
#open(ciphertext) ⇒ String Also known as: decrypt
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rbnacl/boxes/sealed.rb', line 113

def open(ciphertext)
  raise CryptoError, "Decryption failed. No private key." unless @private_key

  ct = ciphertext
  raise CryptoError, "Decryption failed. Ciphertext failed verification." if ct.bytesize < SEALBYTES

  message = Util.zeros(ct.bytesize - SEALBYTES)

  success = self.class.box_seal_open(message, ct, ct.bytesize, @public_key.to_s, @private_key.to_s)
  raise CryptoError, "Decryption failed. Ciphertext failed verification." unless success

  message
end
#primitive ⇒ Symbol

The crypto primitive for the box class

131
132
133
# File 'lib/rbnacl/boxes/sealed.rb', line 131

def primitive
  self.class.primitive
end

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4