PHP Classes

File: src/Util.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   HPKE PHP   src/Util.php   Download  
File: src/Util.php
Role: Class source
Content type: text/plain
Description: Class source
Class: HPKE PHP
Encrypt and decrypt data using hybrid public keys
Author: By
Last change:
Date: 8 days ago
Size: 587 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);
namespace
ParagonIE\HPKE;

use
GMP;
use
SodiumException;

class
Util
{
   
/**
     * @throws SodiumException
     */
   
public static function gmpToBytes(GMP $input, int $length): string
   
{
       
$unpadded = gmp_strval($input, 16);
        return
sodium_hex2bin(str_pad(
           
$unpadded,
           
$length << 1,
           
'0',
           
STR_PAD_LEFT
       
));
    }

   
/**
     * @throws SodiumException
     */
   
public static function bytesToGmp(string $buf): GMP
   
{
        return
gmp_init(sodium_bin2hex($buf), 16);
    }
}