本文整理汇总了PHP中Crypt_RSA::createKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Crypt_RSA::createKey方法的具体用法?PHP Crypt_RSA::createKey怎么用?PHP Crypt_RSA::createKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Crypt_RSA
的用法示例。
在下文中一共展示了Crypt_RSA::createKey方法的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']));
}
示例2: signNewCert
function signNewCert()
{
if (!$GLOBALS['isCA']) {
return false;
} else {
$CAPrivKey = new Crypt_RSA();
$CAPrivKey->loadKey($GLOBALS['CAPrivKeyStr']);
$CAx509 = new File_X509();
$CAx509->loadX509($GLOBALS['CAPubX509']);
//认证证书
$privKey = new Crypt_RSA();
$keyArray = $CAPrivKey->createKey($GLOBALS['RSALength']);
$privKey->loadKey($keyArray['privatekey']);
$pubKey = new Crypt_RSA();
$pubKey->loadKey($keyArray['publickey']);
$pubKey->setPublicKey();
$subject = new File_X509();
$subject->setDNProp('id-at-organizationName', $GLOBALS['CAname'] . ' cert');
$subject->setPublicKey($pubKey);
$issuer = new File_X509();
$issuer->setPrivateKey($CAPrivKey);
$issuer->setDN($CAx509->getDN());
$x509 = new File_X509();
$result = $x509->sign($issuer, $subject);
return array('privateKey' => $privKey->getPrivateKey(), 'publicX509' => $x509->saveX509($result));
}
}
示例3: createKeys
protected function createKeys()
{
$rsa = new Crypt_RSA();
$keypair = $rsa->createKey(2048);
$this['private_key'] = preg_replace("/\r/", "", $keypair['privatekey']);
$this['public_key'] = preg_replace("/\r/", "", $keypair['publickey']);
}
示例4:
function generate_key_pair($user_id)
{
$rsa = new Crypt_RSA();
$keypair = $rsa->createKey();
update_user_meta($user_id, "magic_sig_public_key", $keypair['publickey']);
update_user_meta($user_id, "magic_sig_private_key", $keypair['privatekey']);
}
示例5: generateAndAdd
function generateAndAdd()
{
$rsa = new \Crypt_RSA();
$rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH);
$this->set($rsa->createKey());
$this->save();
}
示例6: createPrivateKey
public function createPrivateKey($sslCnfPath)
{
$rsa = new Crypt_RSA();
$rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
$keyPair = $rsa->createKey();
return array('public' => $keyPair['publickey'], 'private' => $keyPair['privatekey']);
}
示例7: generate_key_pair
function generate_key_pair($user_id)
{
$rsa = new Crypt_RSA();
$keypair = $rsa->createKey();
// FIXME: Should we put 'ocf_' before these?
set_custom_field($user_id, 'magic_sig_public_key', $keypair['publickey']);
set_custom_field($user_id, 'magic_sig_private_key', $keypair['privatekey']);
}
示例8: 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;
}
示例9: 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);
}
示例10: createKeys
private static function createKeys()
{
$rsa = new \Crypt_RSA();
$aKeys = $rsa->createKey(512);
if (empty($aKeys)) {
throw new \Exception("Key generation failed...");
}
$sKeyPath = __DIR__ . "/../../AppBundle/Resources/private/api/keys/server/";
file_put_contents($sKeyPath . "private.key", $aKeys['privatekey']);
file_put_contents($sKeyPath . "public.key", $aKeys['publickey']);
}
示例11: createKeys
public static function createKeys()
{
$rsa = new \Crypt_RSA();
$aKeys = $rsa->createKey(512);
if (empty($aKeys)) {
throw new \Exception("Key generation failed...");
}
$sAppPath = self::$_container->get('kernel')->getRootDir();
$sKeyPath = $sAppPath . "/../vendor/slashworks/control-bundle/src/Slashworks/AppBundle/Resources/private/api/keys/server/";
file_put_contents($sKeyPath . "private.key", $aKeys['privatekey']);
file_put_contents($sKeyPath . "public.key", $aKeys['publickey']);
}
示例12: 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'];
}
示例13: newKeys
private function newKeys()
{
set_time_limit(30000);
$path = get_include_path();
$rsa = new Crypt_RSA();
$keys = $rsa->createKey($this->bits);
set_include_path($path);
if ($this->type == "filegallery") {
FileGallery\File::filename($this->certName)->setParam("description", $this->certName)->replace(json_encode($keys));
}
if ($this->type == "file") {
file_put_contents("temp/" . $this->certName, json_encode($keys));
}
return $keys;
}
示例14: 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;
}
示例15: testSaveSPKAC
public function testSaveSPKAC()
{
$privKey = new Crypt_RSA();
extract($privKey->createKey());
$privKey->loadKey($privatekey);
$x509 = new File_X509();
$x509->setPrivateKey($privKey);
$x509->setChallenge('...');
$spkac = $x509->signSPKAC();
$this->assertInternalType('array', $spkac);
$this->assertInternalType('string', $x509->saveSPKAC($spkac));
$x509 = new File_X509();
$x509->setPrivateKey($privKey);
$spkac = $x509->signSPKAC();
$this->assertInternalType('array', $spkac);
$this->assertInternalType('string', $x509->saveSPKAC($spkac));
}