mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Add RSA encryption/decryption helper
This commit is contained in:
parent
f9e709af5b
commit
f5248d8ac2
41
app/Helpers/Encrypt/Secure.php
Normal file
41
app/Helpers/Encrypt/Secure.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
}
|
@ -233,5 +233,9 @@ return [
|
|||||||
'turnstile' => [
|
'turnstile' => [
|
||||||
'secret' => env('CLOUDFLARE_SECRET', null),
|
'secret' => env('CLOUDFLARE_SECRET', null),
|
||||||
]
|
]
|
||||||
]
|
],
|
||||||
|
'encryption' => [
|
||||||
|
'public_key' => env('NINJA_PUBLIC_KEY', false),
|
||||||
|
'private_key' => env('NINJA_PRIVATE_KEY', false),
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user