Private key encryption logic

The client's private key is encrypted using openssl library. AES-256-CBC encryption type, sha256 hash type.

An example of encryption implemented in PHP:

   public function encrypt(string $privateKey, string $encryptedKey): ?string
   {
       $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('AES-256-CBC'));
       $ciphertextRaw = openssl_encrypt($privateKey, 'AES-256-CBC', $encryptedKey, OPENSSL_RAW_DATA, $iv);
       $hmac = hash_hmac('sha256', $ciphertextRaw, $encryptedKey, true);


       return base64_encode($iv . $hmac . $ciphertextRaw);
   }

Last updated