mirror of
https://codeberg.org/vlw/php-age.git
synced 2025-09-14 08:23:42 +02:00
feat(doc): add README
This commit is contained in:
parent
690faf3bb1
commit
d3bfb7ecd1
1 changed files with 52 additions and 0 deletions
52
README.md
Normal file
52
README.md
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
# PHP wrapper for the [age command line encryption tool](https://github.com/FiloSottile/age)
|
||||||
|
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.
|
||||||
|
|
||||||
|
```php
|
||||||
|
$age = new FileEncryption("hello.txt");
|
||||||
|
$age->encrypt("hello.txt.age", "hello.txt.age.key");
|
||||||
|
```
|
||||||
|
```php
|
||||||
|
$age = new FileEncryption("hello.txt.age");
|
||||||
|
$age->decrypt("hello.txt.age.key", "hello-decrypted.txt");
|
||||||
|
```
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
1. [Install the age command line tool](https://github.com/FiloSottile/age#installation)
|
||||||
|
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:
|
||||||
|
```php
|
||||||
|
require_once "vendor/autoload.php";
|
||||||
|
|
||||||
|
use \Age\FileEncryption;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Encrypt a file
|
||||||
|
Encrypt a file on disk by passing it to the `FileEncryption` constructor
|
||||||
|
```php
|
||||||
|
// 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()`
|
||||||
|
```php
|
||||||
|
// 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
|
||||||
|
```php
|
||||||
|
// 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");
|
||||||
|
```
|
Loading…
Add table
Reference in a new issue