Exemplo n.º 1
0
 /**
  * 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() . ".");
 }