PHP Classes

File: src/Context/Receiver.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   HPKE PHP   src/Context/Receiver.php   Download  
File: src/Context/Receiver.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: 720 bytes
 

Contents

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

class
Receiver extends Context
{
    const
ROLE = Role::Receiver;

   
/**
     * @throws HPKEException
     */
   
public function open(
       
string $ciphertext,
       
string $aad = ''
   
): string {
       
$Nt = $this->hpke->aead->tagLength();
       
$ct = substr($ciphertext, 0, -$Nt);
       
$tag = substr($ciphertext, -$Nt, $Nt);
       
$pt = $this->hpke->aead->decrypt(
           
$this->key,
           
$ct,
           
$tag,
           
$this->computeNonce(),
           
$aad
       
);
       
$this->incrementSeq();
        return
$pt;
    }
}