PHP wrapper for the age file encryption command line tool
Find a file
2023-08-23 15:16:56 +02:00
src initial commit 2023-08-22 17:42:27 +02:00
.gitignore initial commit 2023-08-22 17:42:27 +02:00
composer.json initial commit 2023-08-22 17:42:27 +02:00
LICENSE initial commit 2023-08-22 17:42:27 +02:00
README.md feat(doc): add README 2023-08-23 15:16:56 +02:00

PHP wrapper for the age command line encryption tool

Encrypt and decrypt files with age from PHP. This library is only a wrapper for the the command line tool, it does not implement the C2CP age specification in PHP.

$age = new FileEncryption("hello.txt");
$age->encrypt("hello.txt.age", "hello.txt.age.key");
$age = new FileEncryption("hello.txt.age");
$age->decrypt("hello.txt.age.key", "hello-decrypted.txt");

Installation

  1. Install the age command line tool
  2. Install this library with composer
    composer require victorwesterlund/php-age
    
  3. Import and use in your project

How to use

Import and use the library:

require_once "vendor/autoload.php";

use \Age\FileEncryption;

Encrypt a file

Encrypt a file on disk by passing it to the FileEncryption constructor

// Relative or absolute path to a file that should be encrypted
$age = new FileEncryption("hello.txt");
// Encrypted file destination and private key destination
// This method also returns the private key as a string
$age->encrypt("hello.txt.age", "hello.txt.age.key");

You can enable optional PEM encoding by chaining armor() before encrypt()

// Encrypt with PEM encoding
$age->armor()->encrypt("hello.txt.age", "hello.txt.age.key");

Decrypt a file

Decrypt a file on disk by passing it to the FileEncryption constructor

// Relative or absolute path to a file that should be decrypted
$age = new FileEncryption("hello.txt.age");
// Private key file and destination of decrypted file
$age->decrypt("hello.txt.age.key", "hello.txt");