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


PHP Crypt_RSA::setPublicKeyFormat方法代码示例

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


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

示例1: buildKeyPair

 /**
  * @param $bits
  * @return KeyPair
  */
 public function buildKeyPair($bits)
 {
     $this->rsa_imp->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
     $this->rsa_imp->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
     $list = $this->rsa_imp->createKey($bits);
     return new KeyPair(new _RSAPublicKeyPEMFornat($list['publickey']), new _RSAPrivateKeyPEMFornat($list['privatekey']));
 }
开发者ID:smarcet,项目名称:jose4php,代码行数:11,代码来源:RSAFacade.php

示例2: generateAndAdd

 function generateAndAdd()
 {
     $rsa = new \Crypt_RSA();
     $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH);
     $this->set($rsa->createKey());
     $this->save();
 }
开发者ID:romaninsh,项目名称:dokku_alt,代码行数:7,代码来源:Access.php

示例3: generateKeyPair

 /**
  * Generate an SSH public / private key pair
  * @return array
  */
 public static function generateKeyPair()
 {
     $publickey = '';
     $privatekey = '';
     $rsa = new \Crypt_RSA();
     $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH);
     extract($rsa->createKey());
     $publickey = str_replace('phpseclib-generated-key', self::SSH_KEY_NAME, $publickey);
     return array($publickey, $privatekey);
 }
开发者ID:primat,项目名称:deployer-org,代码行数:14,代码来源:SshTask.php

示例4: generateSshKeys

 private function generateSshKeys()
 {
     $rsa = new \Crypt_RSA();
     $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH);
     $rsa->setPassword(\OC::$server->getConfig()->getSystemValue('secret', ''));
     $key = $rsa->createKey();
     // Replace the placeholder label with a more meaningful one
     $key['publicKey'] = str_replace('phpseclib-generated-key', gethostname(), $key['publickey']);
     return $key;
 }
开发者ID:heldernl,项目名称:owncloud8-extended,代码行数:10,代码来源:ajaxcontroller.php

示例5: generateKey

 /**
  * Generates random key with optonal passphrase and stores it
  * in the model
  */
 function generateKey($pack = null)
 {
     $rsa = new Crypt_RSA();
     if ($pack) {
         $rsa->setPassword($pack);
     }
     $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH);
     $key = $rsa->createKey();
     $this['kind'] = 'key';
     $this['host'] = '*';
     $this['data'] = $key['privatekey'];
     $this['is_secure'] = (bool) $pack;
     $this['notes'] = $key['publickey'];
 }
开发者ID:kmattimo,项目名称:dokku-alt-manager,代码行数:18,代码来源:Keychain.php

示例6: creat_public_key

 public function creat_public_key()
 {
     $oldIncludePath = get_include_path();
     $include = realpath(dirname(__FILE__));
     set_include_path($include . DIRECTORY_SEPARATOR . 'CryptLib');
     include_once 'Crypt/RSA.php';
     $rsa = new Crypt_RSA();
     $rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
     $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
     //define('CRYPT_RSA_EXPONENT', 65537);
     //define('CRYPT_RSA_SMALLEST_PRIME', 64); // makes it so multi-prime RSA is used
     $a = $rsa->createKey();
     // == $rsa->createKey(1024) where 1024 is the key size
     return $a;
 }
开发者ID:congnn,项目名称:betoja,代码行数:15,代码来源:My_encrypt.php

示例7: encrypt

 public function encrypt()
 {
     $binaryKey = bin2hex(base64_decode(GOOGLE_DEFAULT_PUBLIC_KEY));
     $half = substr($binaryKey, 8, 256);
     $modulus = new Math_BigInteger(hex2bin($half), 256);
     $half = substr($binaryKey, 272, 6);
     $exponent = new Math_BigInteger(hex2bin($half), 256);
     $sha1 = sha1(base64_decode($googleDefaultPublicKey), true);
     $signature = "00" . bin2hex(substr($sha1, 0, 4));
     $rsa = new Crypt_RSA();
     $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_RAW);
     $rsa->loadKey(array("n" => $modulus, "e" => $exponent));
     $rsa->setPublicKey();
     $plain = "{$email}{$password}";
     $rsa->setEncryptionMode("CRYPT_RSA_ENCRYPTION_OAEP");
     $encrypted = bin2hex($rsa->encrypt($plain));
     $output = hex2bin($signature . $encrypted);
     $b64EncryptedPasswd = str_replace(array("+", "/"), array("-", "_"), mb_convert_encoding(base64_encode($output), "US-ASCII"));
     return $b64EncryptedPasswd;
 }
开发者ID:mgp25,项目名称:Google-Crypto,代码行数:20,代码来源:encrypt.php

示例8: encryptPassword

 public function encryptPassword($email, $password)
 {
     $googleDefaultPublicKey = "AAAAgMom/1a/v0lblO2Ubrt60J2gcuXSljGFQXgcyZWveWLEwo6prwgi3iJIZdodyhKZQrNWp5nKJ3srRXcUW+F1BD3baEVGcmEgqaLZUNBjm057pKRI16kB0YppeGx5qIQ5QjKzsR8ETQbKLNWgRY0QRNVz34kMJR3P/LgHax/6rmf5AAAAAwEAAQ==";
     $binaryKey = bin2hex(base64_decode($googleDefaultPublicKey));
     $half = substr($binaryKey, 8, 256);
     $modulus = new Math_BigInteger(hex2bin($half), 256);
     $half = substr($binaryKey, 272, 6);
     $exponent = new Math_BigInteger(hex2bin($half), 256);
     $sha1 = sha1(base64_decode($googleDefaultPublicKey), true);
     $signature = "00" . bin2hex(substr($sha1, 0, 4));
     $rsa = new Crypt_RSA();
     $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_RAW);
     $rsa->loadKey(array("n" => $modulus, "e" => $exponent));
     $rsa->setPublicKey();
     $plain = "{$email}{$password}";
     $rsa->setEncryptionMode("CRYPT_RSA_ENCRYPTION_OAEP");
     $encrypted = bin2hex($rsa->encrypt($plain));
     $output = hex2bin($signature . $encrypted);
     $b64EncryptedPasswd = str_replace(array("+", "/"), array("-", "_"), mb_convert_encoding(base64_encode($output), "US-ASCII"));
     return $b64EncryptedPasswd;
 }
开发者ID:krew25,项目名称:SC-API,代码行数:21,代码来源:snapchat.php

示例9: rsa_encrypt

 public function rsa_encrypt($input_str, $key)
 {
     $rsa = new Crypt_RSA();
     $rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
     $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
     $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
     $public_key = array('n' => new Math_BigInteger($key, 16), 'e' => new Math_BigInteger('65537', 10));
     $rsa->loadKey($public_key, CRYPT_RSA_PUBLIC_FORMAT_RAW);
     return $rsa->encrypt($input_str);
 }
开发者ID:demenvil,项目名称:BitScrow,代码行数:10,代码来源:bit-sci.lib.php

示例10: git_ssh_gen

 public function git_ssh_gen()
 {
     //errors need to be on while experimental
     error_reporting(E_ALL);
     ini_set("display_errors", 1);
     $gitpath = preg_replace("#/\$#", "", sanitize_text_field($_POST['sshpath']));
     //create the folder if doesn't exist
     if (!file_exists($gitpath)) {
         mkdir($gitpath, 0700);
     }
     //create known hosts if doesn't exist
     if (!file_exists($gitpath . "/known_hosts")) {
         touch($gitpath . "/known_hosts");
         chmod($gitpath . "/known_hosts", 0700);
     }
     //create keys if not exist
     if (!file_exists($gitpath . "/id_rsa") || !file_exists($gitpath . "/id_rsa.pub")) {
         set_include_path(get_include_path() . PATH_SEPARATOR . plugin_dir_path(__FILE__) . 'git/phpseclib');
         include 'Crypt/RSA.php';
         $rsa = new Crypt_RSA();
         $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH);
         extract($rsa->createKey());
         // == $rsa->createKey(1024) where 1024 is the key size - $privatekey and $publickey
         //create private key
         file_put_contents($gitpath . "/id_rsa", $privatekey);
         chmod($gitpath . "/id_rsa", 0700);
         //create public key
         file_put_contents($gitpath . "/id_rsa.pub", $publickey);
         chmod($gitpath . "/id_rsa.pub", 0700);
     }
     //return public key
     echo "\n\n" . file_get_contents($gitpath . "/id_rsa.pub") . "\n\n";
     die;
 }
开发者ID:2braincells2go,项目名称:WPide,代码行数:34,代码来源:WPide.php

示例11:

<?php

set_time_limit(0);
if (file_exists('private.key')) {
    echo base64_encode(file_get_contents('private.key'));
} else {
    include 'Crypt/RSA.php';
    $rsa = new Crypt_RSA();
    $rsa->setHash('sha1');
    $rsa->setMGFHash('sha1');
    $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_OAEP);
    $rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
    $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
    $res = $rsa->createKey(1024);
    $privateKey = $res['privatekey'];
    $publicKey = $res['publickey'];
    file_put_contents('public.key', $publicKey);
    file_put_contents('private.key', $privateKey);
    echo base64_encode($privateKey);
}
开发者ID:fajarlabs,项目名称:php_security,代码行数:20,代码来源:keypair.php

示例12: exit

     exit('Critical error while installing ! Unable to write to /conf/secret.keys.ini !');
 }
 if (is_writable(CONF_API_KEY_INI)) {
     $handle = fopen(CONF_API_KEY_INI, 'w');
     $data = "; API KEY FILE\nAPP_API_KEY \t\t= \"" . $APP_API_KEY . "\"\n";
     fwrite($handle, $data);
     fclose($handle);
     unset($handle);
 } else {
     exit('Critical error while installing ! Unable to write to /conf/api.conf.ini !');
 }
 //---------------------------------------------------------+
 // Generating RSA Keys
 if (is_writable(RSA_KEYS_DIR)) {
     $rsa = new Crypt_RSA();
     $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH);
     $keypair = $rsa->createKey(2048);
     $handle = fopen(RSA_PRIVATE_KEY_FILE, 'w');
     $data = $keypair['privatekey'];
     fwrite($handle, $data);
     fclose($handle);
     unset($handle);
     $handle = fopen(RSA_PUBLIC_KEY_FILE, 'w');
     $data = $keypair['publickey'];
     fwrite($handle, $data);
     fclose($handle);
     unset($handle);
 } else {
     exit('Critical error while installing ! Unable to write to /app/crypto/ !');
 }
 //---------------------------------------------------------+
开发者ID:master3395,项目名称:bgpanelv2,代码行数:31,代码来源:index.php

示例13: encrypt_value

 public static function encrypt_value($encrypt_key_id, $value)
 {
     $encrypt_key = self::get_encrypt_key($encrypt_key_id);
     if ($encrypt_key && $encrypt_key['public_key']) {
         $dir = getcwd();
         chdir('includes/plugin_encrypt/phpseclib/');
         require_once 'Crypt/RSA.php';
         chdir($dir);
         // if encrypt fails return plain tet
         $rsa = new Crypt_RSA();
         //echo "Public Key: '".$encrypt_key['public_key']."'\n\n";
         $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_RAW);
         $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
         $public_key = array('n' => new Math_BigInteger($encrypt_key['public_key'], 16), 'e' => new Math_BigInteger($encrypt_key['e'], 16));
         $rsa->loadKey($public_key, CRYPT_RSA_PUBLIC_FORMAT_RAW);
         $ciphertext = $rsa->encrypt($value);
         return bin2hex($ciphertext);
     }
     return false;
 }
开发者ID:sgh1986915,项目名称:php-crm,代码行数:20,代码来源:encrypt.php

示例14: dummy

<?php

if (!isset($_POST) || empty($_POST['pcname'])) {
    exit;
}
set_include_path(get_include_path() . PATH_SEPARATOR . 'lib');
include 'lib/Crypt/RSA.php';
$rsa = new Crypt_RSA();
$rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_XML);
$rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_XML);
extract($rsa->createKey(2048));
$pcname = $_POST['pcname'];
$username = $_POST['username'];
include 'db.php';
$stmt = $connection->prepare('INSERT INTO dummy (pcname, username, privatekey) VALUES (?, ?, ?)');
$stmt->execute([$pcname, $username, $privatekey]);
//var_dump($privatekey);
echo $publickey;
开发者ID:chienthan9x,项目名称:eda2,代码行数:18,代码来源:createkeys.php

示例15: DoGetPublicKey

 /**
  * @return array
  */
 public function DoGetPublicKey()
 {
     if ($this->Config()->Get('security', 'use_rsa_encryption', false)) {
         \RainLoop\Service::$__HIDE_ERROR_NOTICES = true;
         if (!\class_exists('Crypt_RSA')) {
             \set_include_path(\get_include_path() . PATH_SEPARATOR . APP_VERSION_ROOT_PATH . 'app/libraries/phpseclib');
             \defined('CRYPT_RSA_MODE') || \define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);
             include_once 'Crypt/RSA.php';
         }
         $oRsa = new \Crypt_RSA();
         $oRsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_RAW);
         $aKeys = $oRsa->createKey(1024);
         if (!empty($aKeys['privatekey']) && !empty($aKeys['publickey']['e']) && !empty($aKeys['publickey']['n'])) {
             $e = new \Math_BigInteger($aKeys['publickey']['e'], 10);
             $n = new \Math_BigInteger($aKeys['publickey']['n'], 10);
             $sHash = \md5($e->toHex() . $n->toHex());
             \RainLoop\Service::$__HIDE_ERROR_NOTICES = false;
             return $this->DefaultResponse(__FUNCTION__, $this->Cacher()->Set(\RainLoop\KeyPathHelper::RsaCacherKey($sHash), $aKeys['privatekey']) ? array($sHash, $e->toHex(), $n->toHex()) : false);
         }
     }
     \RainLoop\Service::$__HIDE_ERROR_NOTICES = false;
     return $this->FalseResponse(__FUNCTION__);
 }
开发者ID:GTAWWEKID,项目名称:tsiserver.us,代码行数:26,代码来源:Actions.php


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