<?php

namespace Sideso\QzLaravel;

use Illuminate\Support\Facades\Storage;


class QzLaravel
{
    public static function sign($data): string
    {
        $key = config('qz-laravel.private_key');
        
        // if(Storage::exists($key)){
        //     $key = Storage::get($key);
        // }
        $privateKey = openssl_get_privatekey(($key), config('qz-laravel.private_key_password')); 
        
        $signature = null;
        openssl_sign($data, $signature, $privateKey, OPENSSL_ALGO_SHA1);

        if ($signature) {
            return base64_encode($signature);
        }

        throw new \Exception('Signature failed');
    }

    public static function publicCertificate(): string
    {
        $key = config('qz-laravel.public_key');

        // if(Storage::exists($key)){
        //     $key = Storage::get($key);
        // }

        return $key;
    }
}