Module: JOSE::JWA::XChaCha20Poly1305_RbNaCl

Extended by:
XChaCha20Poly1305_RbNaCl
Included in:
XChaCha20Poly1305_RbNaCl
Defined in:
lib/jose/jwa/xchacha20poly1305_rbnacl.rb

Instance Method Summary collapse

Instance Method Details

#__ruby__?Boolean

Returns:

  • (Boolean)


5
# File 'lib/jose/jwa/xchacha20poly1305_rbnacl.rb', line 5

def __ruby__?; false; end

#__supported__?Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jose/jwa/xchacha20poly1305_rbnacl.rb', line 7

def __supported__?
  return @supported ||= begin
    begin
      require 'rbnacl/libsodium'
    rescue LoadError
    end
    begin
      require 'rbnacl'
    rescue LoadError
    end
    !!(defined?(RbNaCl::AEAD::XChaCha20Poly1305IETF))
  end
end

#xchacha20poly1305_aead_decrypt(key, nonce, aad, ciphertext, tag) ⇒ Object



27
28
29
30
31
# File 'lib/jose/jwa/xchacha20poly1305_rbnacl.rb', line 27

def xchacha20poly1305_aead_decrypt(key, nonce, aad, ciphertext, tag)
  cipher = RbNaCl::AEAD::XChaCha20Poly1305IETF.new(key)
  ciphertext_with_tag = [ciphertext, tag].join()
  return cipher.decrypt(nonce, ciphertext_with_tag, aad)
end

#xchacha20poly1305_aead_encrypt(key, nonce, aad, plaintext) ⇒ Object



21
22
23
24
25
# File 'lib/jose/jwa/xchacha20poly1305_rbnacl.rb', line 21

def xchacha20poly1305_aead_encrypt(key, nonce, aad, plaintext)
  cipher = RbNaCl::AEAD::XChaCha20Poly1305IETF.new(key)
  ciphertext_with_tag = cipher.encrypt(nonce, plaintext, aad)
  return [ciphertext_with_tag[0..-17], ciphertext_with_tag[-16..-1]]
end