1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Helpers/Encrypt/Secure.php

42 lines
996 B
PHP
Raw Normal View History

2023-12-23 06:09:03 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
2023-12-23 06:09:03 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Helpers\Encrypt;
class Secure
{
public static function encrypt(string $hash): ?string
{
$data = null;
$public_key = openssl_pkey_get_public(config('ninja.encryption.public_key'));
if (openssl_public_encrypt($hash, $encrypted, $public_key)) {
$data = base64_encode($encrypted);
}
return $data;
}
public static function decrypt(string $hash): ?string
{
$data = null;
$private_key = openssl_pkey_get_private(config('ninja.encryption.private_key'));
if (openssl_private_decrypt(base64_decode($hash), $decrypted, $private_key)) {
$data = $decrypted;
}
return $data;
}
2024-01-14 05:05:00 +01:00
}