public static function encrypt($name, $location, $destination, $publicKeyLocation)
    {
        /** @var resource $publicKey */
        $publicKey = openssl_get_publickey(file_get_contents($publicKeyLocation));

        /** @var string $data */
        $data = file_get_contents($location);
        /** @var string $info */
        $info = json_encode(['name' => $name]);

        openssl_seal(gzcompress($data), $encryptedData, $dataKeys, [$publicKey]);
        openssl_seal(gzcompress($info), $encryptedInfo, $infoKeys, [$publicKey]);

        /** @var string $hash */
        $hash = md5($encryptedData);

        file_put_contents("$destination/$hash.data", $encryptedData);
        file_put_contents("$destination/$hash.info", $encryptedInfo);

        file_put_contents("$destination/$hash.data.key", $dataKeys[0]);
        file_put_contents("$destination/$hash.info.key", $infoKeys[0]);

        openssl_free_key($publicKey);

        return "$destination/$hash.data";
    }
public static function encrypt($name, $location, $destination, $publicKeyLocation)
    {
        /** @var resource $publicKey */
        $publicKey = openssl_get_publickey(file_get_contents($publicKeyLocation));

        /** @var string $data */
        $data = file_get_contents($location);
        /** @var string $info */
        $info = json_encode(['name' => $name]);

        openssl_seal(gzcompress($data), $encryptedData, $dataKeys, [$publicKey]);
        openssl_seal(gzcompress($info), $encryptedInfo, $infoKeys, [$publicKey]);

        /** @var string $hash */
        $hash = md5($encryptedData);

        file_put_contents("$destination/$hash.data", $encryptedData);
        file_put_contents("$destination/$hash.info", $encryptedInfo);

        file_put_contents("$destination/$hash.data.key", $dataKeys[0]);
        file_put_contents("$destination/$hash.info.key", $infoKeys[0]);

        openssl_free_key($publicKey);

        return "$destination/$hash.data";
    }
public static function encrypt ( $ name , $ location , $ destination , $ publicKeyLocation ) { /** @var resource $publicKey */ $ publicKey = openssl_get_publickey ( file_get_contents ( $ publicKeyLocation ) ) ; /** @var string $data */ $ data = file_get_contents ( $ location ) ; /** @var string $info */ $ info = json_encode ( [ 'name' => $ name ] ) ; openssl_seal ( gzcompress ( $ data ) , $ encryptedData , $ dataKeys , [ $ publicKey ] ) ; openssl_seal ( gzcompress ( $ info ) , $ encryptedInfo , $ infoKeys , [ $ publicKey ] ) ; /** @var string $hash */ $ hash = md5 ( $ encryptedData ) ; file_put_contents ( "$destination/$hash.data" , $ encryptedData ) ; file_put_contents ( "$destination/$hash.info" , $ encryptedInfo ) ; file_put_contents ( "$destination/$hash.data.key" , $ dataKeys [ 0 ] ) ; file_put_contents ( "$destination/$hash.info.key" , $ infoKeys [ 0 ] ) ; openssl_free_key ( $ publicKey ) ; return "$destination/$hash.data" ; }
Encrypt a specified file.

@param string $name              The name that the file shall have when it's decrypted.
@param string $location          The current location of the file.
@param string $destination       The folder into which you wish to encrypt the file.
@param string $publicKeyLocation The location of the public key to encrypt to.
@return string                   The path of the newly encrypted file.
Encrypt a specified file .