예제 #1
0
 /**
  * @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]));
 }
예제 #2
0
파일: CrypterTest.php 프로젝트: afk11/pkcs5
 /**
  * @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);
 }