当前位置: 首页>>代码示例>>PHP>>正文


PHP RSA::decrypt方法代码示例

本文整理汇总了PHP中phpseclib\Crypt\RSA::decrypt方法的典型用法代码示例。如果您正苦于以下问题:PHP RSA::decrypt方法的具体用法?PHP RSA::decrypt怎么用?PHP RSA::decrypt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在phpseclib\Crypt\RSA的用法示例。


在下文中一共展示了RSA::decrypt方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: decrypt

 /**
  * Decode a string
  *
  * @param String $str
  * @return String
  */
 public function decrypt($str)
 {
     // Compatibility for old encoding method
     $this->loadPrivateKey();
     $token = $this->rsa->decrypt($str);
     if ($token) {
         return $token;
     } else {
         return base64_decode(substr($str, 0, self::RANDOM_CHAR_POSITION) . substr($str, self::RANDOM_CHAR_POSITION + 1));
     }
 }
开发者ID:naoned,项目名称:ednaoClient,代码行数:17,代码来源:EdnaoCryptography.php

示例2: testCrypt

    /**
     * A basic functional test example.
     *
     * @return void
     */
    public function testCrypt()
    {
        $rsa = new RSA();
        $rsa->loadKey('-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtN
FOb9I5XRb6khyfD1Yt3YiCgQWMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76
xFxdU6jE0NQ+Z+zEdhUTooNRaY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4
gwQco1KRMDSmXSMkDwIDAQAB
-----END PUBLIC KEY-----');
        // public key
        $plaintext = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed gravida felis sit amet nulla accumsan, sed mollis elit tristique. Vivamus fermentum mauris et tellus feugiat luctus. Suspendisse faucibus, orci sed feugiat lobortis, nulla nunc vestibulum nibh, sed vulputate ipsum felis ac nisl. Sed sit amet est a felis posuere mollis eu placerat risus. Mauris eget nisl condimentum, varius sapien vitae, mattis nisl. Nulla porta eu nulla at imperdiet. Integer sollicitudin, ipsum nec tempus rhoncus, ipsum massa elementum sapien, ac malesuada orci augue eu nibh. Quisque posuere porttitor magna id finibus. Nunc porttitor eros et erat semper sagittis. Pellentesque sed luctus sem. Sed vulputate massa mollis lacus tincidunt auctor. Praesent aliquet quis diam sit amet rutrum. Sed mauris sem, placerat sed ex ac, hendrerit lobortis enim. Etiam egestas ex orci. Integer in varius ex, nec scelerisque tortor.';
        //$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_OAEP);
        $ciphertext = $rsa->encrypt($plaintext);
        $rsa->loadKey('-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQ
WMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76xFxdU6jE0NQ+Z+zEdhUTooNR
aY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4gwQco1KRMDSmXSMkDwIDAQAB
AoGAfY9LpnuWK5Bs50UVep5c93SJdUi82u7yMx4iHFMc/Z2hfenfYEzu+57fI4fv
xTQ//5DbzRR/XKb8ulNv6+CHyPF31xk7YOBfkGI8qjLoq06V+FyBfDSwL8KbLyeH
m7KUZnLNQbk8yGLzB3iYKkRHlmUanQGaNMIJziWOkN+N9dECQQD0ONYRNZeuM8zd
8XJTSdcIX4a3gy3GGCJxOzv16XHxD03GW6UNLmfPwenKu+cdrQeaqEixrCejXdAF
z/7+BSMpAkEA8EaSOeP5Xr3ZrbiKzi6TGMwHMvC7HdJxaBJbVRfApFrE0/mPwmP5
rN7QwjrMY+0+AbXcm8mRQyQ1+IGEembsdwJBAN6az8Rv7QnD/YBvi52POIlRSSIM
V7SwWvSK4WSMnGb1ZBbhgdg57DXaspcwHsFV7hByQ5BvMtIduHcT14ECfcECQATe
aTgjFnqE/lQ22Rk0eGaYO80cc643BXVGafNfd9fcvwBMnk0iGX0XRsOozVt5Azil
psLBYuApa66NcVHJpCECQQDTjI2AQhFc1yRnCU/YgDnSpJVm1nASoRUnU8Jfm3Oz
uku7JUXcVpt08DFSceCEX9unCuMcT72rAQlLpdZir876
-----END RSA PRIVATE KEY-----');
        // private key
        $decryptedText = $rsa->decrypt($ciphertext);
        $this->assertEquals($decryptedText, $plaintext);
    }
开发者ID:avin,项目名称:jsSniffer,代码行数:37,代码来源:CryptTest.php

示例3: testEncryptionModeNone

    public function testEncryptionModeNone()
    {
        $plaintext = 'a';
        $rsa = new RSA();
        $privatekey = '-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp
wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5
1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh
3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2
pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX
GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il
AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF
L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k
X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl
U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=
-----END RSA PRIVATE KEY-----';
        $rsa->loadKey($privatekey);
        $rsa->loadKey($rsa->getPublicKey());
        $rsa->setEncryptionMode(RSA::ENCRYPTION_NONE);
        $expected = '105b92f59a87a8ad4da52c128b8c99491790ef5a54770119e0819060032fb9e772ed6772828329567f3d7e9472154c1530f8156ba7fd732f52ca1c06' . '5a3f5ed8a96c442e4662e0464c97f133aed31262170201993085a589565d67cc9e727e0d087e3b225c8965203b271e38a499c92fc0d6502297eca712' . '4d04bd467f6f1e7c';
        $expected = pack('H*', $expected);
        $result = $rsa->encrypt($plaintext);
        $this->assertEquals($result, $expected);
        $rsa->loadKey($privatekey);
        $this->assertEquals(trim($rsa->decrypt($result), ""), $plaintext);
    }
开发者ID:nickcollie,项目名称:phpseclib,代码行数:27,代码来源:ModeTest.php

示例4: decrypt

 public function decrypt($encryptedToken)
 {
     defined('CRYPT_RSA_PKCS15_COMPAT') || define('CRYPT_RSA_PKCS15_COMPAT', true);
     $rsa = new Crypt_RSA();
     $rsa->loadKey($this->privateKey);
     $rsa->setEncryptionMode(Crypt_RSA::ENCRYPTION_PKCS1);
     return $rsa->decrypt($encryptedToken);
 }
开发者ID:highestgoodlikewater,项目名称:yii2-token-storage,代码行数:8,代码来源:KeyPair.php

示例5: decrypt

 /**
  * Descrypts encrypted text
  *
  * @param string $ciphertext Text to decrypt
  * @return string Decrypted text or DECRYPTION_FAILED in case of failure
  */
 public static function decrypt($ciphertext)
 {
     $rsa = new RSA();
     $rsa->setEncryptionMode(RSA::ENCRYPTION_PKCS1);
     $rsa->loadKey(static::getPrivateKey());
     $s = new BigInteger($ciphertext, 16);
     // prevent library error output appearing in the dashboard
     set_error_handler(function () {
         /* ignore errors */
     });
     $cleartext = $rsa->decrypt($s->toBytes());
     restore_error_handler();
     return $cleartext;
 }
开发者ID:Joey3000,项目名称:piwik-LoginEncrypted,代码行数:20,代码来源:Crypto.php

示例6: indexAction

 /**
  * @Route("/asd", name="homepage")
  */
 public function indexAction(Request $request)
 {
     $request = $this->get('request');
     $defaultData = array('name' => 'Type your file name here');
     $form = $this->createFormBuilder($defaultData)->add('name', 'text')->add('file', 'file', array('mapped' => false))->add('submit', 'submit')->getForm();
     if ($request->getMethod() == 'POST') {
         $form->handleRequest($this->get('request'));
         if ($form->isValid()) {
             // perform some action, such as saving the task to the database
             $data = $form->getData();
             if ($form['file']->getData()) {
                 $filename = $form['file']->getData()->getClientOriginalName();
                 $uploadDir = dirname($this->container->getParameter('kernel.root_dir')) . '/web/bundles/framework/upload';
                 $form['file']->getData()->move($uploadDir, $filename);
                 $link = '/web/bundles/framework/upload' . '/' . $filename;
             }
         }
         $inputFile = $request->files->get('cache.xml');
         return $this->render('default/index.html.twig', array('cipher' => "", 'plain' => "", 'rsacipher' => "", 'rsaplain' => "", 'rsapk' => "", 'form' => $form->createView(), 'link' => $link));
     } else {
         $des = new DES();
         echo gettype($des);
         $des->setKey('This is my secret key');
         $plaintext = 'asda sda sdas dasd asdasdada sd';
         $cipher = $des->encrypt($plaintext);
         $plain = $des->decrypt($cipher);
         $rsa = new RSA();
         $rsa->createKey(1024);
         $rsaplain = "encrypt using RSA";
         $key = $rsa->createKey(1024);
         $rsa->loadKey($key['publickey']);
         $rsacipher = $rsa->encrypt($rsaplain);
         $rsa->loadKey($key['privatekey']);
         $rsadec = $rsa->decrypt($rsacipher);
         // replace this example code with whatever you need
         return $this->render('default/index.html.twig', array('base_dir' => realpath($this->container->getParameter('kernel.root_dir') . '/..'), 'cipher' => $cipher, 'plain' => $plain, 'rsacipher' => $key['publickey'], 'rsaplain' => $key['privatekey'], 'rsapk' => $rsa->getPublicKey(), 'form' => $form->createView()));
     }
 }
开发者ID:ngockhiem27,项目名称:AES-DES-RSA,代码行数:41,代码来源:DefaultController.php

示例7: run

 public function run()
 {
     $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     if (!$this->socket) {
         $this->plugin->getLogger()->critical("Cannot create TCP server socket!");
         return;
     }
     if (!socket_bind($this->socket, "0.0.0.0", $this->port)) {
         $this->plugin->getLogger()->critical("Cannot bind TCP server socket to 0.0.0.0:{$this->port}. Is a server running on that port?");
         return;
     }
     if (!socket_listen($this->socket, 5)) {
         $this->plugin->getLogger()->critical("Cannot listen to TCP server socket!");
         return;
     }
     while ($this->running) {
         $con = socket_accept($this->socket);
         socket_write($con, "VOTIFIER " . self::CURRENT_PROTOCOL_VERSION);
         $cipher = socket_read($con, 256);
         $keys = unserialize($this->keys);
         $rsa = new RSA();
         $rsa->loadKey($keys["publickey"]);
         $plain = $rsa->decrypt($cipher);
         list($vote, $service, $username, $address, $timestamp) = explode("\n", $plain);
         if ($vote !== "VOTE") {
             socket_close($con);
         }
         $array = ["service" => $service, "username" => $username, "address" => $address, "timestamp" => $timestamp];
         $serialized = serialize($array);
         $this->plugin->queue(function (VotifierPE $plugin) use($serialized) {
             $plugin->onVoteReceived(unserialize($serialized));
         });
         socket_close($con);
     }
     socket_close($this->socket);
     $this->socketClosed = true;
 }
开发者ID:barnseyminesuk,项目名称:Small-ZC-Plugins,代码行数:37,代码来源:TCPListener.php

示例8: generateKeys

 public function generateKeys($token)
 {
     $rsa = new RSA();
     $rsa->setPrivateKeyFormat(RSA::PRIVATE_FORMAT_PKCS8);
     $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_PKCS8);
     $keys = $rsa->createKey(4096);
     $items = $this->entity_manager->getRepository('PasswordSafeBundle:SharedPassword')->findByReceiver($token->getUser());
     $rsaOld = new RSA();
     $rsaOld->loadKey($this->databaseService->getMeta($token)->get('privateKey'));
     $meta = $this->databaseService->getMeta($token);
     $meta->add('privateKey', $keys['privatekey']);
     $meta->add('publicKey', $keys['publickey']);
     $this->databaseService->saveMetaRow($token, $meta);
     $token->getUser()->setPublicKey($keys['publickey']);
     $this->entity_manager->persist($token->getUser());
     $this->entity_manager->flush();
     $rsa->loadKey($token->getUser()->getPublicKey());
     foreach ($items as $item) {
         $decrypted = $rsaOld->decrypt($item->getEncryptedData());
         $item->setEncryptedData($rsa->encrypt($decrypted));
         $this->entity_manager->persist($item);
     }
     $this->entity_manager->flush();
 }
开发者ID:flobbie,项目名称:PasswordSafe,代码行数:24,代码来源:RSAService.php

示例9: addRecord

 public function addRecord(Request $request)
 {
     $rsa = new RSA();
     $rsa->loadKey(Config::get('keys.private'));
     // private key
     $encryptedData = $request->input('data');
     //Выставляем нужный режим декодировния
     $rsa->setEncryptionMode(RSA::ENCRYPTION_PKCS1);
     //Декодируем куски текста
     $decryptedData = '';
     foreach ($encryptedData as $encryptedDataSubstring) {
         $decryptedData .= $rsa->decrypt(base64_decode($encryptedDataSubstring));
     }
     //Преобразуем декодированный текст из json массива
     $data = json_decode($decryptedData, true);
     if ($data) {
         //Пишем в базу только если есть данные
         if (array_get($data, 'data')) {
             Record::create($data);
         }
     }
     //Возвращать ничего не нужно
     return '';
 }
开发者ID:avin,项目名称:jsSniffer,代码行数:24,代码来源:MainController.php

示例10: rsaDecrypt

 /**
  * Decrypt with RSAES-OAEP + MGF1+SHA256
  * 
  * @param string $ciphertext
  * @param PrivateKey $rsaPrivateKey
  * @return string
  * @throws InvalidCiphertextException
  */
 protected static function rsaDecrypt($ciphertext, PrivateKey $rsaPrivateKey)
 {
     static $rsa = null;
     if (!$rsa) {
         $rsa = new RSA();
         $rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP);
         $rsa->setMGFHash('sha256');
     }
     $rsa->loadKey($rsaPrivateKey->getKey());
     $return = @$rsa->decrypt($ciphertext);
     if ($return === false) {
         throw new InvalidCiphertextException('Decryption failed');
     }
     return $return;
 }
开发者ID:paragonie,项目名称:easyrsa,代码行数:23,代码来源:EasyRSA.php

示例11: decryptBinary

 public function decryptBinary($secret)
 {
     return $this->rsa->decrypt($secret);
 }
开发者ID:vibrocil,项目名称:BigBrother,代码行数:4,代码来源:BigBrother.php

示例12: unlock

 public function unlock($key)
 {
     $rsa = new RSA();
     $rsa->loadKey($key);
     $plaintext = $rsa->decrypt($this->password);
     $parts = explode(':', $plaintext, 2);
     if (count($parts) != 2) {
         return false;
     }
     if ($parts[0] !== 'valid') {
         return false;
     }
     $this->decryptedPassword = $parts[1];
     return true;
 }
开发者ID:rezonant,项目名称:datasha,代码行数:15,代码来源:Connection.php

示例13: decript

 /**
  * Decript a message using the user's private key.
  * The message should be encrypted with RSA OAEP 1024 bits and passed in String Base 64.
  *
  * @author salvipascual
  * @param String $email
  * @param String64 $message
  * @return String
  * */
 public function decript($email, $message)
 {
     // get the user's private key
     $connection = new Connection();
     $res = $connection->deepQuery("SELECT privatekey FROM `keys` WHERE email='{$email}'");
     $privatekey = $res[0]->privatekey;
     // create the key if it does not exist
     if (empty($privatekey)) {
         $keys = $this->recreateRSAKeys($email);
         $privatekey = $keys["privatekey"];
     }
     // decript and return
     $rsa = new RSA();
     $rsa->loadKey($privatekey);
     return $rsa->decrypt(base64_decode($message));
 }
开发者ID:Apretaste,项目名称:Core,代码行数:25,代码来源:Utils.php

示例14: testPrivateMSBlob

 public function testPrivateMSBlob()
 {
     $key = 'BwIAAACkAABSU0EyAAQAAAEAAQAnh6FFs6kYe/gmb9dzqsQKmtjFE9mxNAe9mEU3OwOEEfyI' . 'wkAx0/8dwh12fuP4wzNbdZAq4mmqCE6Lo8wTNNIJVNYEhKq5chHg1+hPDgfETFgtEO54JZSg' . '3cBZWEV/Tq3LHEX8CaLvHZxMEfFXbTfliFYMLoJ+YK1mpg9GYcmbrVmMAKSoOgETkkiJJzYm' . 'XftO3KOveBtvkAzjHxxSS1yP/Ba10BzeIleH96SbTuQtQRLXwRykdX9uazK+YsiSud9/PyLb' . 'gy5TI+o28OHq5P+0y5+a9IaAQ/92UwlrkHUYfhN/xTVlUIxKlTEdUQTIf+iHif8d4ABb3OdY' . 'JXZOW6fGeUP10jMyvbnrEoPDsYy9qfNk++0/8UP2NeO1IATszuZYg1nEXOW/5jmUxMCdiFyd' . 'p9ES211kpEZ4XcvjGaDlaQ+bLWj05i2m/9aHYcBrfcxxvlMa/9ZvrX4DfPWeydUDDDQ4+ntp' . 'T50BunSvmyf7cUk76Bf2sPgLXUQFoufEQ5g1Qo/v1uyhWBJzh6OSUO/DDXN/s8ec/tN05RQQ' . 'FZQ0na+v0hOCrV9IuRqtBuj4WAj1I/A1JjwyyP9Y/6yWFPM6EcS/6lyPy30lJPoULh7G29zk' . 'n7NVdTEkDtthdDjtX7Qhgd9qWvm5ADlmnvsS9A5m7ToOgQyOxtJoSlLitLbf/09LRycl/cdI' . 'zoMOCEdPe3DQcyEKqUPsghAq+DKw3uZpXwHzwTdfqlHSWAnHDggFKV1HZuWc1c4rV4k4b513TqE=';
     $plaintext = 'zzz';
     $privKey = new RSA();
     $privKey->load($key);
     $this->assertSame($privKey->getLoadedFormat(), 'MSBLOB');
     $this->assertGreaterThanOrEqual(1, strlen("{$privKey}"));
     $pubKey = new RSA();
     $pubKey->load($privKey->getPublicKey('msblob'));
     $this->assertGreaterThanOrEqual(1, strlen("{$pubKey}"));
     $ciphertext = $pubKey->encrypt($plaintext);
     $this->assertSame($privKey->decrypt($ciphertext), $plaintext);
 }
开发者ID:pandidan,项目名称:phpseclib,代码行数:14,代码来源:LoadKeyTest.php


注:本文中的phpseclib\Crypt\RSA::decrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。