Project

ece

0.01
No commit activity in last 3 years
No release in over 3 years
Ruby implementation of encrypted content-encoding
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 12.3.3

Runtime

>= 0
 Project Readme

ECE

Ruby implementation of encrypted content-encoding.

https://tools.ietf.org/html/draft-thomson-http-encryption-02

Installation

Add this line to your application's Gemfile:

gem 'ece'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ece

Usage

Encrypting:

require 'ece'

key = Random.new.bytes(16)
salt = Random.new.bytes(16)
data = "Your very private data"

encrypted_data = ECE.encrypt(data, key: key, salt: salt)

Decrypting:

ECE.decrypt(encrypted_data, key: key, salt: salt)

Data can be bytestring as well.

Encrypting data with elliptical curve Diffie-Hellman (ECDH) key agreement protocol using client keys providing by a Web Push subscription:

user_public_key # Provided by the browser, effectively: Random.new.bytes(65)
user_auth # Provided by the browser, effectively: Random.new.bytes(16)

local_curve = OpenSSL::PKey::EC.new("prime256v1")
local_curve.generate_key
user_public_key_point = OpenSSL::PKey::EC::Point.new(local_curve.group, OpenSSL::BN.new(user_public_key, 2))

key = local_curve.dh_compute_key(user_public_key_point)
server_public_key = local_curve.public_key.to_bn.to_s(2)
salt = Random.new.bytes(16)

encrypted_data = ECE.encrypt(data,
  key: key,
  salt: salt
  server_public_key: server_public_key,
  user_public_key: user_public_key,
  auth: user_auth)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/randomlogin/ece.