/** * @param Pkcs8PrivateKey $privateKey * @param string $password * @return Sequence */ public function getEncryptedPrivateKeyInfo(Pkcs8PrivateKey $privateKey, $password) { $digestParams = $privateKey->getKdfParams(); $cipherParams = $privateKey->getCipherParams(); $pkcs5Info = $this->pkcs5->getPkcs5Data($digestParams, $cipherParams); $encKey = $this->digester->digest($password, $digestParams); $data = $this->getPrivateKeyInfo($privateKey); $cipherText = $this->crypter->encrypt($data->getBinary(), $encKey, $cipherParams); return new Sequence($pkcs5Info, new OctetString(unpack("H*", $cipherText)[1])); }
/** * @expectedException \RuntimeException * @expectedExceptionMessage Unknown or unsupported cipher */ public function testUnknownCipherDecrypt() { $mock = $this->getMockBuilder(CipherParamsInterface::class)->setMethods(['getName'])->getMock(); $digester = new Crypter(); $digester->decrypt('data', 'aaaaaaaaaaaaaaaa', $mock); }