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


PHP RSA::encrypt方法代码示例

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


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

示例1: 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

示例2: 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

示例3: doLogin

 /**
  * Login with the set username and password.
  * @return LoginResult
  * @throws SteamException Thrown when Steam gives an unexpected response (e.g. Steam is down/having issues)
  * @throws \Exception Thrown when cookiefile is unable to be created.
  */
 public function doLogin()
 {
     if (!file_exists($this->_getCookiesFilePath())) {
         if (file_put_contents($this->_getCookiesFilePath(), '') === false) {
             throw new \Exception("Could not create cookiefile for {$this->username}.");
         }
     }
     if ($this->_isLoggedIn()) {
         $this->loggedIn = true;
         return LoginResult::LoginOkay;
     }
     $rsaResponse = $this->cURL('https://steamcommunity.com/login/getrsakey', null, ['username' => $this->username]);
     $rsaJson = json_decode($rsaResponse, true);
     if ($rsaJson == null) {
         return LoginResult::GeneralFailure;
     }
     if (!$rsaJson['success']) {
         return LoginResult::BadRSA;
     }
     $rsa = new RSA();
     $rsa->setEncryptionMode(RSA::ENCRYPTION_PKCS1);
     $key = ['modulus' => new BigInteger($rsaJson['publickey_mod'], 16), 'publicExponent' => new BigInteger($rsaJson['publickey_exp'], 16)];
     $rsa->loadKey($key, RSA::PUBLIC_FORMAT_RAW);
     $encryptedPassword = base64_encode($rsa->encrypt($this->password));
     $params = ['username' => $this->username, 'password' => urlencode($encryptedPassword), 'twofactorcode' => is_null($this->twoFactorCode) ? '' : $this->twoFactorCode, 'captchagid' => $this->requiresCaptcha ? $this->captchaGID : '-1', 'captcha_text' => $this->requiresCaptcha ? $this->captchaText : '', 'emailsteamid' => $this->requires2FA || $this->requiresEmail ? (string) $this->steamId : '', 'emailauth' => $this->requiresEmail ? $this->emailCode : '', 'rsatimestamp' => $rsaJson['timestamp'], 'remember_login' => 'false'];
     $loginResponse = $this->cURL('https://steamcommunity.com/login/dologin/', null, $params);
     $loginJson = json_decode($loginResponse, true);
     if ($loginJson == null) {
         return LoginResult::GeneralFailure;
     } else {
         if (isset($loginJson['captcha_needed']) && $loginJson['captcha_needed']) {
             $this->requiresCaptcha = true;
             $this->captchaGID = $loginJson['captcha_gid'];
             return LoginResult::NeedCaptcha;
         } else {
             if (isset($loginJson['emailauth_needed']) && $loginJson['emailauth_needed']) {
                 $this->requiresEmail = true;
                 $this->steamId = $loginJson['emailsteamid'];
                 return LoginResult::NeedEmail;
             } else {
                 if (isset($loginJson['requires_twofactor']) && $loginJson['requires_twofactor'] && !$loginJson['success']) {
                     $this->requires2FA = true;
                     return LoginResult::Need2FA;
                 } else {
                     if (isset($loginJson['login_complete']) && !$loginJson['login_complete']) {
                         return LoginResult::BadCredentials;
                     } else {
                         if ($loginJson['success']) {
                             $this->_setSession();
                             $this->loggedIn = true;
                             return LoginResult::LoginOkay;
                         }
                     }
                 }
             }
         }
     }
     return LoginResult::GeneralFailure;
 }
开发者ID:botsolutions,项目名称:PHP-SteamCommunity,代码行数:65,代码来源:SteamCommunity.php

示例4: encrypt

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

示例5: encrypt

 public function encrypt(DatabaseRow $row, User $receiver)
 {
     $rsa = new RSA();
     $rsa->loadKey($receiver->getPublicKey());
     $rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP);
     $sharedRow = clone $row;
     $sharedRow->setAttributes(array());
     return $rsa->encrypt(json_encode($sharedRow));
 }
开发者ID:flobbie,项目名称:PasswordSafe,代码行数:9,代码来源:RSAService.php

示例6: testSmallModulo

 /**
  * @expectedException \LengthException
  */
 public function testSmallModulo()
 {
     $plaintext = 'x';
     $n = new BigInteger(base64_decode('272435F22706FA96DE26E980D22DFF67'), 256);
     $e = new BigInteger(base64_decode('158753FF2AF4D1E5BBAB574D5AE6B54D'), 256);
     $rsa = new RSA();
     $rsa->load(array('n' => $n, 'e' => $e));
     $rsa->encrypt($plaintext);
 }
开发者ID:bengitiger,项目名称:phpseclib,代码行数:12,代码来源:ModeTest.php

示例7: login

 public function login($user_id, $user_pw, $do_finalize = true)
 {
     $keys = $this->getKeys();
     $rsa = new RSA();
     $rsa->modulus = new BigInteger($keys['nvalue'], 16);
     $rsa->exponent = new BigInteger($keys['evalue'], 16);
     $rsa->publicExponent = new BigInteger($keys['evalue'], 16);
     $rsa->k = strlen($rsa->modulus->toBytes());
     $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
     $rsa->loadKey($rsa->_convertPublicKey($rsa->modulus, $rsa->exponent), CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
     $raw_data = $this->getLenChar($keys['sessionkey']) . $keys['sessionkey'] . $this->getLenChar($user_id) . $user_id . $this->getLenChar($user_pw) . $user_pw;
     $enc_data = $rsa->encrypt($raw_data);
     $login_url = 'https://nid.naver.com/nidlogin.login';
     $headers = ['User-Agent' => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 TAKOYAKI", 'Accept' => 'text/html,application/xhtml+xml,' . 'application/xml;q=0.9,*/*;q=0.8', 'Accept-Language' => 'ko-KR,ko;q=0.8,en-US;q=0.5,en;q=0.3', 'Accept-Encoding' => 'gzip, deflate', 'Referer' => 'http://www.naver.com/', 'Content-Type' => 'application/x-www-form-urlencoded'];
     $params = "enctp" . "=" . "1";
     $params .= "&encpw" . "=" . bin2hex($enc_data);
     $params .= "&encnm" . "=" . $keys['keyname'];
     $params .= "&svctype" . "=" . "0";
     $params .= "&url=http://www.naver.com/&enc_url=http%3A%2F%2Fwww.naver.com%2F&postDataKey=&nvlong=&saveID=&smart_level=undefined";
     $params .= "&id" . "=" . "";
     $params .= "&pw" . "=" . "";
     $resp = $this->postURL($login_url, $params, 10, $headers);
     // echo "\n\nheader\n" . $resp ["header"] . "\n";
     // echo "\n\nbody\n" . $resp ["body"] . "\n";
     $this->logined = true;
     echo "\n로그인에 성공했습니다\n";
     if (strpos($resp["body"], "새로운")) {
         // NEW DEVICE CHECK
         $key = $this->getKey($resp["body"]);
         $result = $this->Accept($key);
         $exp = explode('Set-Cookie: ', $result);
         $NID_SES3 = explode('Set-Cookie: NID_AUT=', $result);
         $work = $NID_SES3[1];
         $NID_SES2 = explode(';', $work);
         $NID_SES = $NID_SES2[0];
         $NID_AUT3 = explode('Set-Cookie: NID_AUT=', $result);
         $work2 = $NID_AUT3[1];
         $NID_AUT2 = explode(';', $work2);
         $NID_AUT = $NID_AUT2[0];
         $this->logined = true;
         echo "\n새장치 등록에 성공했습니다\n";
     } elseif (strpos($resp["body"], "않습니다")) {
         $this->logined = false;
     }
     if ($do_finalize and strpos($resp["body"], "https://nid.naver.com/login/sso/finalize.nhn")) {
         $finalize_url = explode("replace(\"", $resp["body"], 2)[1];
         $finalize_url = explode("\")", $finalize_url, 2)[0];
         // echo "finalize_url: " . $finalize_url . "\n";
         $headers = ['User-Agent' => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 TAKOYAKI", 'Accept' => 'text/html,application/xhtml+xml,' . 'application/xml;q=0.9,*/*;q=0.8', 'Accept-Language' => 'ko-KR,ko;q=0.8,en-US;q=0.5,en;q=0.3', 'Accept-Encoding' => 'gzip, deflate', 'Referer' => 'https://nid.naver.com/nidlogin.login'];
         $resp = $this->postURL($finalize_url, $headers);
         echo "파이널라이즈에 성공했습니다\n";
         // var_dump ( $resp );
     }
 }
开发者ID:HerO-0110,项目名称:EmailAuth,代码行数:54,代码来源:NaverSession.php

示例8: generateSecret

 protected function generateSecret($password)
 {
     $finder = new Finder();
     $root = $this->container->get('kernel')->getRootDir();
     $files = $finder->ignoreUnreadableDirs()->in($root . 'key/')->files()->name('uipubkey.pem');
     foreach ($files as $file) {
         $private_key_text = $file->getContent();
         break;
     }
     if (!$private_key_text) {
         throw new FileNotFoundException('Encryption key not found');
     }
     $rsa = new RSA();
     $rsa->loadKey($private_key_text);
     return base64_encode($rsa->encrypt($password));
 }
开发者ID:kawashita86,项目名称:gpanel,代码行数:16,代码来源:Webservice.php

示例9: 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

示例10: encrypt

 /**
  * Encrypt with the public key.
  *
  * @param $string
  *
  * @return string base64 encoded
  */
 public function encrypt($string)
 {
     return base64_encode($this->rsa_key->encrypt($string));
 }
开发者ID:drdelay,项目名称:steam-login,代码行数:11,代码来源:SteamRSAKey.php

示例11: lock

 public function lock()
 {
     $rsa = new RSA();
     $rsa->loadKey($this->publicKey);
     $this->password = $rsa->encrypt("valid:" . $this->decryptedPassword);
     $this->decryptedPassword = null;
 }
开发者ID:rezonant,项目名称:datasha,代码行数:7,代码来源:Connection.php

示例12: encript

 /**
  * Encript a message using the user's public key.
  *
  * @author salvipascual
  * @param String $email
  * @param String $message
  * @return String64
  * */
 public function encript($email, $message)
 {
     // get the user's public key
     $connection = new Connection();
     $res = $connection->deepQuery("SELECT publickey FROM `keys` WHERE email='{$email}'");
     $publickey = $res[0]->publickey;
     // create the key if it does not exist
     if (empty($publickey)) {
         $keys = $this->recreateRSAKeys($email);
         $publickey = $keys["publickey"];
     }
     // encript and return
     $rsa = new RSA();
     $rsa->loadKey($publickey);
     $rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP);
     return base64_encode($rsa->encrypt($message));
 }
开发者ID:Apretaste,项目名称:Core,代码行数:25,代码来源:Utils.php

示例13: 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

示例14: _encryptPrivateKey

 /**
  * Encrypt a secret key packet.
  *
  * @param OpenPGP_SecretKeyPacket $p    Secret key packet.
  * @param \phpseclib\Crypt\RSA $cipher  RSA cipher object.
  * @param OpenPGP_S2K $s2k              OpenPGP String-to-key object.
  * @param string $iv                    Initial vector.
  */
 protected function _encryptPrivateKey($p, $cipher, $s2k, $iv)
 {
     $cipher->setIV($iv);
     $secret = '';
     foreach ($p::$secret_key_fields[$p->algorithm] as $f) {
         $f = $p->key[$f];
         $secret .= pack('n', OpenPGP::bitlength($f)) . $f;
     }
     $secret .= hash('sha1', $secret, true);
     $p->encrypted_data = $iv . $cipher->encrypt($secret);
     $p->s2k = $s2k;
     $p->s2k_useage = 254;
     $p->symmetric_algorithm = 7;
 }
开发者ID:horde,项目名称:horde,代码行数:22,代码来源:Openpgp.php

示例15: rsaEncrypt

 /**
  * Decrypt with RSAES-OAEP + MGF1+SHA256
  * 
  * @param string $plaintext
  * @param PublicKey $rsaPublicKey
  * @return string
  * @throws InvalidCiphertextException
  */
 protected static function rsaEncrypt($plaintext, PublicKey $rsaPublicKey)
 {
     static $rsa = null;
     if (!$rsa) {
         $rsa = new RSA();
         $rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP);
         $rsa->setMGFHash('sha256');
     }
     $rsa->loadKey($rsaPublicKey->getKey());
     return $rsa->encrypt($plaintext);
 }
开发者ID:paragonie,项目名称:easyrsa,代码行数:19,代码来源:EasyRSA.php


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