Jose\Util\ConcatKDF::generate PHP Méthode

generate() public static méthode

Key Derivation Function.
public static generate ( string $Z, string $algorithm, integer $encryption_key_size, string $apu = '', string $apv = '' ) : string
$Z string Shared secret
$algorithm string Encryption algorithm
$encryption_key_size integer Size of the encryption key
$apu string Agreement PartyUInfo (information about the producer)
$apv string Agreement PartyVInfo (information about the recipient)
Résultat string
    public static function generate($Z, $algorithm, $encryption_key_size, $apu = '', $apv = '')
    {
        $apu = !empty($apu) ? Base64Url::decode($apu) : '';
        $apv = !empty($apv) ? Base64Url::decode($apv) : '';
        $encryption_segments = [self::toInt32Bits(1), $Z, self::toInt32Bits(mb_strlen($algorithm, '8bit')) . $algorithm, self::toInt32Bits(mb_strlen($apu, '8bit')) . $apu, self::toInt32Bits(mb_strlen($apv, '8bit')) . $apv, self::toInt32Bits($encryption_key_size), ''];
        $input = implode('', $encryption_segments);
        $hash = hash('sha256', $input, true);
        $kdf = mb_substr($hash, 0, $encryption_key_size / 8, '8bit');
        return $kdf;
    }

Usage Example

Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function getAgreementKey($encryption_key_length, $algorithm, JWKInterface $recipient_key, array $complete_header = [], array &$additional_header_values = [])
 {
     if ($recipient_key->has('d')) {
         $this->checkKey($recipient_key, true);
         $private_key = $recipient_key;
         $public_key = $this->getPublicKey($complete_header);
     } else {
         $this->checkKey($recipient_key, false);
         $public_key = $recipient_key;
         switch ($public_key->get('crv')) {
             case 'P-256':
             case 'P-384':
             case 'P-521':
                 $private_key = JWKFactory::createECKey(['crv' => $public_key->get('crv')]);
                 break;
             case 'X25519':
                 $private_key = JWKFactory::createOKPKey(['crv' => 'X25519']);
                 break;
             default:
                 throw new \InvalidArgumentException(sprintf('The curve "%s" is not supported', $public_key->get('crv')));
         }
         $epk = $private_key->toPublic()->getAll();
         $additional_header_values = array_merge($additional_header_values, ['epk' => $epk]);
     }
     Assertion::eq($private_key->get('crv'), $public_key->get('crv'), 'Curves are different');
     $agreed_key = $this->calculateAgreementKey($private_key, $public_key);
     $apu = array_key_exists('apu', $complete_header) ? $complete_header['apu'] : '';
     $apv = array_key_exists('apv', $complete_header) ? $complete_header['apv'] : '';
     return ConcatKDF::generate($agreed_key, $algorithm, $encryption_key_length, $apu, $apv);
 }
All Usage Examples Of Jose\Util\ConcatKDF::generate