vlucas / pikirasa

PKI public/private RSA key encryption using the OpenSSL extension
BSD 3-Clause "New" or "Revised" License
102 stars 21 forks source link

Feature request - Private Encryption #16

Open emichristiansen opened 4 years ago

emichristiansen commented 4 years ago

Hi, I've been working with your library! Great Job, I really like it. I'd like to ask if it is possible to add private encryption and public decryption.

For example


public function encrypt($data) 
{
        if ($this->privateKeyFile === null) {
            throw new Exception("Unable to encrypt: No private key provided.");
        }

        $privateKey = openssl_pkey_get_private($this->privateKeyFile, $this->password);
        if (!$privateKey) {
            throw new Exception("OpenSSL: Unable to get private key for encryption");
        }

        $success = openssl_private_encrypt($data, $encryptedData, $privateKey);
        openssl_free_key($privateKey);
        if (!$success) {
            throw new Exception("Encryption failed. Ensure you are using (1) A PRIVATE key, and (2) the correct one.");
        }

        return $encryptedData;
    }

I'm using it with Laravel Lumen, as soon as I learn how, I'd like to make a package for laravel

Cheers