mirror of
https://codeberg.org/vlw/php-age.git
synced 2025-09-14 00:13:42 +02:00
PHP wrapper for the age file encryption command line tool
src | ||
.gitignore | ||
composer.json | ||
LICENSE | ||
README.md |
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
- Install the age command line tool
- Install this library with composer
composer require victorwesterlund/php-age
- 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");