Elliptic Curve Integrated Encryption Scheme for secp256k1 in Ruby.
This is a Ruby port of eciespy.
Make sure you have secp256k1 and openssl installed, if not:
brew install secp256k1 opensslThen set environment variables:
export C_INCLUDE_PATH=$(brew --prefix secp256k1)/includegem install eciesrb# examples/quickstart.rbrequire"ecies"# Generate a secret keysk=Ecies.generate_keyraw_sk=Ecies.decode_hex(sk.send(:serialize))raw_pk=sk.pubkey.serialize(compressed: false)# Encrypt data with the receiver's public keyplaintext="Hello, World!"encrypted=Ecies.encrypt(raw_pk,plaintext)# Decrypt data with the receiver's secret keydecrypted=Ecies.decrypt(raw_sk,encrypted)putsdecrypted# => "Hello, World!"You can customize the encryption behavior using a Config object:
# examples/config.rbrequire"ecies"Ecies::DEFAULT_CONFIG.is_ephemeral_key_compressed=true# Use compressed ephemeral public keyEcies::DEFAULT_CONFIG.is_hkdf_key_compressed=true# Use compressed key for HKDFEcies::DEFAULT_CONFIG.symmetric_nonce_length=16# Nonce length for AES-GCM (default: 16)is_ephemeral_key_compressed(Boolean): Whether to use compressed format for the ephemeral public key. Default:falseis_hkdf_key_compressed(Boolean): Whether to use compressed format for HKDF key derivation. Default:falsesymmetric_nonce_length(Integer): The nonce length for AES-GCM encryption. Options:12,16. Default:16
Encrypts data using the receiver's public key.
Parameters:
receiver_pk(String): The receiver's public key (raw bytes, serialized)data(String): The plaintext data to encrypt (raw bytes)config(Ecies::Config): Optional configuration object
Returns: (String) The encrypted data (ephemeral public key + encrypted data)
Decrypts data using the receiver's secret key.
Parameters:
receiver_sk(String): The receiver's secret key (raw bytes, serialized)data(String): The encrypted data (ephemeral public key + encrypted data)config(Ecies::Config): Optional configuration object
Returns: (String) The decrypted plaintext data (raw bytes)
See CHANGELOG.md.
