Project

age.rb

0.0
No release in over 3 years
age.rb: Ruby bindings for age
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

~> 1.17
 Project Readme

The age logo, a wireframe of St. Peters dome in Rome, with the text: age, file encryption

age.rb: Ruby bindings for age

Gem Version Ruby Reference Contributors License

Ruby bindings for age using a CGO shared library with FFI bindings.

Age is a simple, modern, and secure file encryption tool, format, and Go library. This gem provides a Ruby interface to age's encryption and decryption capabilities.

Features

  • Encrypt and decrypt data using age public/private key pairs, passphrase, and SSH keys
  • Encrypt and decrypt files directly
  • Generate age keypairs programmatically, optionally with post-quantum keys
  • Multiple recipients and identies support for encryption and decryption
  • ASCII armor format support for text-safe encrypted output
  • FFI-based integration with Go's age implementation
  • Binary data handling with proper encoding

Requirements

  • Go >= 1.25 (for building the Go extension)
  • Ruby >= 3.2.3
  • libffi-dev (for FFI support)

Installation

Add this line to your application's Gemfile:

gem 'age.rb'

And then execute:

bundle install

Or install it yourself as:

gem install age.rb

Building from Source

  1. Clone the repository:

    git clone https://github.com/tschaefer/age.rb.git
    cd age.rb
  2. Install dependencies:

    bundle install
  3. Build and install:

    bundle exec rake install

Usage

require 'age'

keypair = Age.generate_keypair(postquantum: true)
# => { public_key: "age1pq1...", private_key: "AGE-SECRET-KEY-PQ..." }

encrypted = Age.encrypt('Hello, Age!', [keypair[:public_key]], armor: true)
# => ASCII armored encrypted string

Age.decrypt(encrypted, keypair[:private_key], armor: true)
# => "Hello, Age!"

For further API documentation generate with YARD:

yard doc --main .index.md

Development

After checking out the repo, run the following to set up your development environment:

# Install Ruby dependencies
bundle install

# Build the Go shared library
cd ext
make
cd ..

# Start a console for experimentation
bundle exec rake console

Running Tests

# Run all tests
bundle exec rake rspec

Code Style

This project uses RuboCop for code style enforcement. Run:

bundle exec rake rubocop

Architecture

This gem uses FFI (Foreign Function Interface) to call functions from a Go shared library (age.so). The Go code wraps the filippo.io/age package and exposes C-compatible functions for:

  • Encrypting data with age public keys, passphrases, and SSH keys (binary and ASCII armor formats)
  • Decrypting data with age private keys, passphrases, and SSH keys (binary and ASCII armor formats)
  • Generating age keypairs
  • Memory management

The Ruby code provides a clean, idiomatic interface to these functions with proper error handling and memory cleanup. SSH key support is provided by the filippo.io/age/agessh package. ASCII armor support is provided by the filippo.io/age/armor package.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tschaefer/age.rb

License

The gem is available as open source under the terms of the BSD-3-Clause License.

Credits

  • age - The underlying encryption tool by Filippo Valsorda
  • filippo.io/age - The Go age library