コード例 #1
0
ファイル: Base.php プロジェクト: rugk/threema-msgapi-sdk-php
 /**
  * @param string $pos
  * @return null|string
  */
 public function getArgumentPublicKey($pos)
 {
     $content = Common::getPublicKey($this->getArgumentStringOrFileContent($pos));
     $cryptTool = CryptTool::getInstance();
     if (null !== $content) {
         return $cryptTool->hex2bin($content);
     }
     return null;
 }
コード例 #2
0
 public function testGetPublicKey()
 {
     $realPublicKey = Common::getPublicKey(Constants::myPublicKey);
     $this->assertEquals($realPublicKey, Constants::myPublicKeyExtract, 'myPublicKey failed');
 }
コード例 #3
0
 public function testEncryptImage()
 {
     $threemaIconContent = file_get_contents(dirname(__FILE__) . '/threema.jpg');
     /** @noinspection PhpUnusedParameterInspection */
     $this->doTest(function (CryptTool $cryptTool, $prefix) use($threemaIconContent) {
         $privateKey = $cryptTool->hex2bin(Common::getPrivateKey(Constants::myPrivateKey));
         $publicKey = $cryptTool->hex2bin(Common::getPublicKey(Constants::myPublicKey));
         $otherPrivateKey = $cryptTool->hex2bin(Common::getPrivateKey(Constants::otherPrivateKey));
         $otherPublicKey = $cryptTool->hex2bin(Common::getPublicKey(Constants::otherPublicKey));
         $result = $cryptTool->encryptImage($threemaIconContent, $privateKey, $otherPublicKey);
         $decryptedImage = $cryptTool->decryptImage($result->getData(), $publicKey, $otherPrivateKey, $result->getNonce());
         $this->assertEquals($decryptedImage, $threemaIconContent, 'decryption of image failed');
     });
 }