From 6c1ae655cdd8edfd23f478a4cb25dde9d1aa5f56 Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Wed, 13 Mar 2024 03:11:59 +0300 Subject: [PATCH] EncryptionHelper --- .../src/Helper/EncryptionHelper.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 com_oauthserver/administrator/src/Helper/EncryptionHelper.php diff --git a/com_oauthserver/administrator/src/Helper/EncryptionHelper.php b/com_oauthserver/administrator/src/Helper/EncryptionHelper.php new file mode 100644 index 0000000..1e8b38b --- /dev/null +++ b/com_oauthserver/administrator/src/Helper/EncryptionHelper.php @@ -0,0 +1,32 @@ + + * @license MIT; see LICENSE.txt + **/ + +namespace Webmasterskaya\Component\OauthServer\Administrator\Helper; + +class EncryptionHelper +{ + public static function generatingKeys(string $alg = 'sha512', int $length = 4096, int $type = OPENSSL_KEYTYPE_RSA, ?string $passphrase = null): array + { + $config = [ + "digest_alg" => $alg, + "private_key_bits" => $length, + "private_key_type" => $type, + "encrypt_key" => !empty($passphrase) + ]; + + $private_key = ''; + $key = openssl_pkey_new($config); + + openssl_pkey_export($key, $private_key, $passphrase); + + $public_key = openssl_pkey_get_details($key); + + return [$private_key, $public_key['key']]; + } +}