/** * Constructor * * @param PBKDF2AlgorithmIdentifier $kdf * @param BlockCipherAlgorithmIdentifier $es */ public function __construct(PBKDF2AlgorithmIdentifier $kdf, BlockCipherAlgorithmIdentifier $es) { parent::__construct($kdf->salt(), $kdf->iterationCount()); $this->_oid = self::OID_PBES2; $this->_kdf = $kdf; $this->_es = $es; }
/** * Constructor * * @param string $salt Salt * @param int $iteration_count Iteration count * @throws \UnexpectedValueException */ public function __construct($salt, $iteration_count) { if (strlen($salt) !== 8) { throw new \UnexpectedValueException("Salt length must be 8 octets."); } parent::__construct($salt, $iteration_count); }
/** * Get PBEScheme by algorithm identifier. * * @param PBEAlgorithmIdentifier $algo * @param Crypto $crypto * @throws \UnexpectedValueException * @return self */ public static function fromAlgorithmIdentifier(PBEAlgorithmIdentifier $algo, Crypto $crypto) { if ($algo->oid() == AlgorithmIdentifier::OID_PBES2) { if (!$algo instanceof PBES2AlgorithmIdentifier) { throw new \UnexpectedValueException("Not a PBES2 algorithm."); } $prf = PRF::fromAlgorithmIdentifier($algo->kdfAlgorithmIdentifier()->prfAlgorithmIdentifier()); return new PBES2($prf, $algo->esAlgorithmIdentifier(), $algo->salt(), $algo->iterationCount(), $crypto); } switch ($algo->oid()) { case AlgorithmIdentifier::OID_PBE_WITH_MD5_AND_DES_CBC: return new PBES1(new MD5(), new DESCBCAlgorithmIdentifier(), $algo->salt(), $algo->iterationCount(), $crypto); case AlgorithmIdentifier::OID_PBE_WITH_MD5_AND_RC2_CBC: return new PBES1(new MD5(), new RC2CBCAlgorithmIdentifier(), $algo->salt(), $algo->iterationCount(), $crypto); case AlgorithmIdentifier::OID_PBE_WITH_SHA1_AND_DES_CBC: return new PBES1(new SHA1(), new DESCBCAlgorithmIdentifier(), $algo->salt(), $algo->iterationCount(), $crypto); case AlgorithmIdentifier::OID_PBE_WITH_SHA1_AND_RC2_CBC: return new PBES1(new SHA1(), new RC2CBCAlgorithmIdentifier(), $algo->salt(), $algo->iterationCount(), $crypto); } throw new \UnexpectedValueException("No encryption scheme for oid " . $algo->oid() . "."); }
/** * Get ASN.1 structure. * * @return Sequence */ public function toASN1() { return new Sequence($this->_algo->toASN1(), new OctetString($this->_data)); }