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


PHP openssl_public_encrypt函数代码示例

本文整理汇总了PHP中openssl_public_encrypt函数的典型用法代码示例。如果您正苦于以下问题:PHP openssl_public_encrypt函数的具体用法?PHP openssl_public_encrypt怎么用?PHP openssl_public_encrypt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: pubCrypt

 public static function pubCrypt($symKey)
 {
     #encrypts a symmetric key and returns it base64
     openssl_public_encrypt($symKey, $encSymKey, self::getPubKey(), OPENSSL_PKCS1_PADDING);
     //OPENSSL_PKCS1_PADDING is the default but setting explicitly because that's what we expect on the server.
     return base64_encode($encSymKey);
 }
开发者ID:arobbins,项目名称:davis,代码行数:7,代码来源:wfCrypt.php

示例2: pubEncrypt

 /**
  * 公钥加密
  */
 public function pubEncrypt($data)
 {
     if (!is_string($data)) {
         return null;
     }
     return openssl_public_encrypt($data, $encrypted, self::getPublicKey()) ? base64_encode($encrypted) : null;
 }
开发者ID:xinson,项目名称:yafPlus,代码行数:10,代码来源:Rsa.php

示例3: post_id_new1_new2_handler

 public function post_id_new1_new2_handler()
 {
     global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['GiveUsMoneyDB']);
     $ret = array('errors' => '');
     $safe = $this->safetyCheck();
     if ($safe !== true) {
         $ret['errors'] = $safe;
     } else {
         $keyfile = realpath(dirname(__FILE__) . '/keys/public.key');
         $pubkey = openssl_pkey_get_public(file_get_contents($keyfile));
         $try = openssl_public_encrypt($this->new1, $encrypted, $pubkey);
         if (!$try) {
             $ret['errors'] = 'Error occurred during encryption';
         } else {
             if ($this->new1 !== $this->new2) {
                 $ret['errors'] = 'New values do not match';
             } else {
                 $model = new GumTaxIdentifiersModel($dbc);
                 $model->card_no($this->id);
                 $model->encryptedTaxIdentifier($encrypted);
                 $model->maskedTaxIdentifier(substr($this->new1, -4));
                 $model->save();
             }
         }
     }
     echo json_encode($ret);
     return false;
 }
开发者ID:phpsmith,项目名称:IS4C,代码行数:29,代码来源:GumTaxIdPage.php

示例4: verifyUtwenteCredentials

 public static function verifyUtwenteCredentials($username, $password)
 {
     // Do weird escape character stuff, because DotEnv doesn't support newlines :(
     $publicKey = str_replace('_!n_', "\n", env('UTWENTEAUTH_KEY'));
     $token = md5(rand());
     // Generate random token
     // Store userdata in array to create JSON later on
     $userData = array('user' => $username, 'password' => $password, 'token' => $token);
     // Encrypt userData in JSON with public key
     openssl_public_encrypt(json_encode($userData), $userDataEncrypted, $publicKey);
     // Start CURL to secureAuth on WESP
     $ch = curl_init(env('UTWENTEAUTH_SRV'));
     // Tell CURL to post encrypted userData in base64
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, "challenge=" . urlencode(base64_encode($userDataEncrypted)));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     // Execute CURL, store response
     $response = curl_exec($ch);
     curl_close($ch);
     // If response matches token, user is verified.
     if ($response == $token) {
         return true;
     }
     return false;
 }
开发者ID:saproto,项目名称:saproto,代码行数:25,代码来源:AuthController.php

示例5: encryptedPin

 /**
  * 证书Id验证密码方法
  * @param $sPin
  * @param $sCardNo
  * @param array $options 参数数组
  * @return array
  */
 function encryptedPin($sPin, $sCardNo, $options)
 {
     $resArr = ['code' => 1];
     $fp = fopen($options['encrypt_cert_path'], "r");
     if ($fp != NULL) {
         $sCrt = fread($fp, 8192);
         fclose($fp);
         $sPubCrt = openssl_x509_read($sCrt);
         if ($sPubCrt === false) {
             $resArr['code'] = 2;
             $resArr['message'] = '读取密码加密证书数据失败';
         } else {
             $pinBlock = new UnionPayPinBlock();
             $sInput = $pinBlock->Pin2PinBlockWithCardNO($sPin, $sCardNo);
             if ($sInput['code'] > 0) {
                 $resArr['code'] = 3;
                 $resArr['message'] = $sInput['message'];
             } else {
                 $iRet = openssl_public_encrypt($sInput['data'], $sOutData, $sCrt, OPENSSL_PKCS1_PADDING);
                 if ($iRet === true) {
                     $resArr['data'] = base64_encode($sOutData);
                 } else {
                     $resArr['code'] = 3;
                     $resArr['message'] = '加密失败';
                 }
             }
         }
     } else {
         $resArr['code'] = 1;
         $resArr['message'] = '打开密码加密证书失败';
     }
     return $resArr;
 }
开发者ID:a07061625,项目名称:pay,代码行数:40,代码来源:UnionPayPublicEncrypt.php

示例6: userAuthAction

 /**
  * @Rest\Post("/users/auth")
  * @param unknown $request
  */
 public function userAuthAction()
 {
     $data = $this->getRequest()->get("data");
     $stringDecrypted = "";
     openssl_private_decrypt(base64_decode($data), $stringDecrypted, openssl_pkey_get_private(file_get_contents(__DIR__ . "/keys/server/private_key_server.pem")));
     $jsonDecrypted = json_decode($stringDecrypted);
     $entityManager = $this->container->get('fos_user.user_manager');
     $user = $entityManager->findUserByUsername($jsonDecrypted->username);
     $encoder_service = $this->get('security.encoder_factory');
     $encoder = $encoder_service->getEncoder($user);
     $encoded_pass = $encoder->isPasswordValid($user->getPassword(), $jsonDecrypted->password, $user->getSalt());
     $token = 0;
     if ($encoded_pass) {
         $currentTime = time();
         $tokenTime = $currentTime + 86400;
         // on day
         $user->setTokenExpiresAt($tokenTime);
         $clearToken = $user->getUsername() . '@' . $tokenTime;
         $shaToken = sha1($clearToken);
         $user->setToken($shaToken);
         $stringCrypted = "";
         $json = "{'token':'" . $clearToken . "'}";
         openssl_public_encrypt($json, $stringCrypted, openssl_pkey_get_public(file_get_contents(__DIR__ . "/keys/server/public_key_mobile.pem")));
         $token = base64_encode($stringCrypted);
         return json_encode(["data" => $token]);
     } else {
         return false;
     }
 }
开发者ID:secureOptimisation,项目名称:WSOptiCloud,代码行数:33,代码来源:RestUserController.php

示例7: decode

 public function decode()
 {
     $core = $this->core;
     list($vMajor, $vMinor) = $core->getVersion();
     // Client
     $connOut = $core->getOutDuplex();
     // Server
     $connIn = $core->getInDuplex();
     // ECDHE
     if ($core->cipherSuite->isECDHEEnabled()) {
         $extensions = $core->extensions;
         $data = $extensions->call('Curve', 'decodeClientKeyExchange', '');
         $preMaster = $extensions->call('Curve', 'getPremaster', null);
     } else {
         $preMaster = Core::_pack('C', $vMajor) . Core::_pack('C', $vMinor) . Core::getRandom(46);
         $crtDers = $core->getCrtDers();
         $publicKey = X509::getPublicKey($crtDers);
         openssl_public_encrypt($preMaster, $encPreMaster, $publicKey);
         $data = Core::_pack('n', strlen($encPreMaster)) . $encPreMaster;
     }
     // Set Master Secret, IV and MAC
     $this->setKeys($preMaster, $connIn, $connOut);
     $this->msgType = HandshakeType::CLIENT_KEY_EXCHANGE;
     $this->length = strlen($data);
     return $this->getBinHeader() . $data;
 }
开发者ID:rnaga,项目名称:php-tls,代码行数:26,代码来源:ClientKeyExchange.php

示例8: encrypt

function encrypt($data, $publicKey)
{
    // Encrypt the data using the public key
    openssl_public_encrypt($data, $encryptedData, $publicKey);
    // Return encrypted data
    return $encryptedData;
}
开发者ID:skydewellers,项目名称:OPENSSL-Cryptography,代码行数:7,代码来源:test.php

示例9: encrypt

 /**
  * Encrypt data using this public key. Data will be decryptable
  * only with the matching private key.
  *
  * This method can only encrypt short data (= shorter than the key,
  * see the PHP manual). To encrypt larger values, use the seal()
  * method.
  *
  * @see     php://openssl_public_encrypt
  * @param   string data
  * @return  string
  * @throws  security.crypto.CryptoException if the operation fails
  */
 public function encrypt($data)
 {
     if (false === openssl_public_encrypt($data, $out, $this->_hdl)) {
         throw new CryptoException('Error encrypting data', OpenSslUtil::getErrors());
     }
     return $out;
 }
开发者ID:xp-framework,项目名称:security,代码行数:20,代码来源:PublicKey.class.php

示例10: publicKeyEncrypt

function publicKeyEncrypt($publicKey, $content)
{
    $pKey = openssl_pkey_get_public($publicKey);
    $encrypted = "";
    openssl_public_encrypt($content, $encrypted, $pKey);
    return base64_encode($encrypted);
}
开发者ID:mysterin,项目名称:myutils,代码行数:7,代码来源:rsa.php

示例11: EncryptedPin

function EncryptedPin($sPin, $sCardNo, $sPubKeyURL)
{
    global $log;
    $sPubKeyURL = trim(SDK_ENCRYPT_CERT_PATH, " ");
    /**
     * [WeEngine System] Copyright (c) 2014 WE7.CC
     * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
     */
    $fp = fopen($sPubKeyURL, "r");
    if ($fp != NULL) {
        $sCrt = fread($fp, 8192);
        fclose($fp);
    }
    $sPubCrt = openssl_x509_read($sCrt);
    if ($sPubCrt === FALSE) {
        print "openssl_x509_read in false!";
        return -1;
    }
    $sPubKey = openssl_x509_parse($sPubCrt);
    $sInput = Pin2PinBlockWithCardNO($sPin, $sCardNo);
    if ($sInput == 1) {
        print "Pin2PinBlockWithCardNO Error ! : " . $sInput;
        return 1;
    }
    $iRet = openssl_public_encrypt($sInput, $sOutData, $sCrt, OPENSSL_PKCS1_PADDING);
    if ($iRet === TRUE) {
        $sBase64EncodeOutData = base64_encode($sOutData);
        return $sBase64EncodeOutData;
    } else {
        print "openssl_public_encrypt Error !";
        return -1;
    }
}
开发者ID:hahamy,项目名称:we7,代码行数:33,代码来源:PublicEncrypte.php

示例12: password_add

function password_add($Name, $Description, $Link, $Username, $Password)
{
    global $pdo;
    echo "Adding password";
    $stmt = $pdo->prepare('insert into `passwords` set
		`name` = :name,
		`description` = :description,
		`link` = :link,
		`username` = :username
	');
    $stmt->bindValue(':name', $Name);
    $stmt->bindValue(':description', $Description);
    $stmt->bindValue(':link', $Link);
    $stmt->bindValue(':username', $Username);
    $stmt->execute();
    $PasswordID = $pdo->lastInsertId();
    // Go through every user, and insert a row for them, using their public key
    $stmt = $pdo->prepare('select * from `users`');
    $stmt->execute();
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        if (is_readable(PATH . 'keys/' . $row['username'] . '.pub')) {
            openssl_public_encrypt($Password, $Encrypted, file_get_contents(PATH . 'keys/' . $row['username'] . '.pub'));
            $stmt = $pdo->prepare('insert into `password_encrypted` set
				`password_id` = :password_id,
				`user_id` = :user_id,
				`blob` = :blob
			');
            $stmt->bindValue(':password_id', $PasswordID, PDO::PARAM_INT);
            $stmt->bindValue(':user_id', $row['id'], PDO::PARAM_INT);
            $stmt->bindValue(':blob', $Encrypted, PDO::PARAM_LOB);
            $stmt->execute();
        }
    }
    return true;
}
开发者ID:ss23,项目名称:Pass-Store,代码行数:35,代码来源:Passwords.php

示例13: encrypt

 function encrypt($text)
 {
     $encryptedText = "";
     openssl_public_encrypt($text, $encryptedText, $this->StringPublicKey);
     $encryptedText = base64_encode($encryptedText);
     return $encryptedText;
 }
开发者ID:frankpaul142,项目名称:chaide,代码行数:7,代码来源:RSAEncryption.php

示例14: EncryptedPin

function EncryptedPin($sPin, $sCardNo, $sPubKeyURL)
{
    global $log;
    $sPubKeyURL = trim(SDK_ENCRYPT_CERT_PATH, " ");
    $fp = fopen($sPubKeyURL, "r");
    if ($fp != NULL) {
        $sCrt = fread($fp, 8192);
        fclose($fp);
    }
    $sPubCrt = openssl_x509_read($sCrt);
    if ($sPubCrt === FALSE) {
        print "openssl_x509_read in false!";
        return -1;
    }
    $sPubKey = openssl_x509_parse($sPubCrt);
    $sInput = Pin2PinBlockWithCardNO($sPin, $sCardNo);
    if ($sInput == 1) {
        print "Pin2PinBlockWithCardNO Error ! : " . $sInput;
        return 1;
    }
    $iRet = openssl_public_encrypt($sInput, $sOutData, $sCrt, OPENSSL_PKCS1_PADDING);
    if ($iRet === TRUE) {
        $sBase64EncodeOutData = base64_encode($sOutData);
        return $sBase64EncodeOutData;
    } else {
        print "openssl_public_encrypt Error !";
        return -1;
    }
}
开发者ID:zhang19960118,项目名称:html11,代码行数:29,代码来源:PublicEncrypte.php

示例15: handshakeAction

 public function handshakeAction()
 {
     $sessStore = Container::getDefaultManager()->getStorage();
     ob_start();
     // get client sected
     $cryptedClientSecred = $this->request->getContent();
     $privKey = openssl_get_privatekey('file:///' . APP_DIR . '/data/keys/server.key');
     openssl_private_decrypt(base64_decode($cryptedClientSecred), $clientSecred, $privKey);
     $sessStore['c_secred'] = $clientSecred;
     // identify client and load public key
     $userid = $this->request->getHeader('X-API-User')->getFieldValue();
     $sessStore['user_id'] = $userid;
     $clientKey = file_get_contents(APP_DIR . '/data/keys/client_' . $userid . '.crt');
     $sessStore['client_key'] = $clientKey;
     // server secred
     $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     $key = '';
     for ($i = 0; $i < 64; $i++) {
         $key .= $characters[mt_rand(0, strlen($characters) - 1)];
     }
     $sessStore['s_secred'] = $key;
     // send server secred
     openssl_public_encrypt($key, $cryptedKey, $clientKey);
     echo base64_encode($cryptedKey);
     $this->response->setContent(ob_get_clean());
     return $this->response;
 }
开发者ID:phiKremer,项目名称:WebDoc,代码行数:27,代码来源:IndexController.php


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