jhehnle/picencrypter

With this simple PHP script you can encrypt and decrypt images.

dev-main 2022-04-04 19:54 UTC

This package is auto-updated.

Last update: 2025-07-05 02:29:27 UTC


README

Hey! This is a simple and single class PHP picture decrypter and encryptor. The images are decrypted and encrypted with openssl. Thus, a variety of encryption options is given.

Usage with composer

Just run composer require jhehnle/picencrypter. Then, all you need to do is to include the autoloader.

// autoload with composer
require_once __DIR__ . '/vendor/autoload.php';

$decrypter = new \jhehnle\picencrypter\picencrypter;

// set the public and private key
$decrypter->public_key = 'user:date';
$decrypter->secret_key = 'mysafeprivatekey';

// encrypt a picture
$decrypter->encode_decode("https://twc-media.de/assets/img/logo.png", 'encrypt');

// decrypt a picture
$decrypter->encode_decode("RFVzOXhWVUdKRVpyNUZyRCtFY...", 'decrypt');

Usage without composer

If you want to use the script without composer, just copy the project into your project and include src/jhehnle/picencrypter.php:

// use without composer
include 'src/jhehnle/picencrypter.php';

Safe a encrypted picture to a file

// encrypt a picture
$decrypter->encode_decode("https://twc-media.de/assets/img/logo.png", 'encrypt');
$decrypter->output = 'file';

This safes the encryptet picture to a file with a uniqe name.

Use another openssl algorithm

// change openssl algorithm
$decrypter->algo = 'AES-256-CBC';

You can use every openssl-compatible algorithm. You can get a complete list with the openssl_get_cipher_methods function in PHP.

Decrypt a picture and only show the Base64- formatting

// decrypt a encrypted picture
$decrypter->encode_decode("RFVzOXhWVUdKRVpyNUZyRCtFY...", 'decrypt');
$decrypter->output = 'str';

This returns not an image but the Base64-String

Version

v1.2.1

License

This project is licensed under the Apache License 2.0. See LICENSE for further information.