lib/pusher/client.rb
def encrypt(channel_name, encoded_data)
      raise ConfigurationError, :encryption_master_key unless @encryption_master_key

      # Only now load rbnacl, so that people that aren't using it don't need to
      # install libsodium
      require_rbnacl

      secret_box = RbNaCl::SecretBox.new(
        channel(channel_name).shared_secret(@encryption_master_key)
      )

      nonce = RbNaCl::Random.random_bytes(secret_box.nonce_bytes)
      ciphertext = secret_box.encrypt(nonce, encoded_data)

      MultiJson.encode({
        "nonce" => Base64::strict_encode64(nonce),
        "ciphertext" => Base64::strict_encode64(ciphertext),
      })
    end
# Encrypts a message with a key derived from the master key and channel
# name
Encrypts a message with a key derived from the master key and channel
name
Encrypts a message with a key derived from the master key and channel name
def encrypt(channel_name, encoded_data)
      raise ConfigurationError, :encryption_master_key unless @encryption_master_key
      require_rbnacl
      secret_box = RbNaCl::SecretBox.new(
        channel(channel_name).shared_secret(@encryption_master_key)
      )
      nonce = RbNaCl::Random.random_bytes(secret_box.nonce_bytes)
      ciphertext = secret_box.encrypt(nonce, encoded_data)
      MultiJson.encode({
        "nonce" => Base64::strict_encode64(nonce),
        "ciphertext" => Base64::strict_encode64(ciphertext),
      })
    end
def encrypt ( channel_name , encoded_data ) raise ConfigurationError , :encryption_master_key unless @encryption_master_key require_rbnacl secret_box = RbNaCl :: SecretBox . new ( channel ( channel_name ) . shared_secret ( @encryption_master_key ) ) nonce = RbNaCl :: Random . random_bytes ( secret_box . nonce_bytes ) ciphertext = secret_box . encrypt ( nonce , encoded_data ) MultiJson . encode ( { "nonce" => Base64 :: strict_encode64 ( nonce ) , "ciphertext" => Base64 :: strict_encode64 ( ciphertext ) , } ) end
Encrypts a message with a key derived from the master key and channel
name
Encrypts a message with a key derived from the master key and channel name
# Only now load rbnacl, so that people that aren't using it don't need to # install libsodium
channel_name
encoded_data