本文整理汇总了PHP中phpseclib\Crypt\RSA::setPrivateKeyFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP RSA::setPrivateKeyFormat方法的具体用法?PHP RSA::setPrivateKeyFormat怎么用?PHP RSA::setPrivateKeyFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpseclib\Crypt\RSA
的用法示例。
在下文中一共展示了RSA::setPrivateKeyFormat方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onEnable
public function onEnable()
{
$this->saveDefaultConfig();
$this->saveResource("server-icon.png", false);
$this->saveResource("steve.yml", false);
$this->saveResource("alex.yml", false);
$this->reloadConfig();
$this->onlineMode = (bool) $this->getConfig()->get("online-mode");
if ($this->onlineMode and !function_exists("mcrypt_generic_init")) {
$this->onlineMode = false;
$this->getLogger()->notice("no mcrypt detected, online-mode has been disabled. Try using the latest PHP binaries");
}
if (!$this->getConfig()->exists("motd")) {
$this->getLogger()->warning("No motd has been set. The server description will be empty.");
return;
}
if (Info::CURRENT_PROTOCOL === 84) {
$this->translator = new Translator_84();
$this->rsa = new RSA();
$this->getServer()->getPluginManager()->registerEvents($this, $this);
Achievement::add("openInventory", "Taking Inventory");
//this for DesktopPlayer
if ($this->onlineMode) {
$this->getLogger()->info("Server is being started in the background");
$this->getLogger()->info("Generating keypair");
$this->rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
$this->rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
$keys = $this->rsa->createKey(1024);
$this->privateKey = $keys["privatekey"];
$this->publicKey = $keys["publickey"];
$this->rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$this->rsa->loadKey($this->privateKey);
}
$this->getLogger()->info("Starting Minecraft: PC server on " . ($this->getIp() === "0.0.0.0" ? "*" : $this->getIp()) . ":" . $this->getPort() . " version " . MCInfo::VERSION);
$disable = true;
foreach ($this->getServer()->getNetwork()->getInterfaces() as $interface) {
if ($interface instanceof ProtocolInterface) {
$disable = false;
}
}
if ($disable) {
$this->interface = new ProtocolInterface($this, $this->getServer(), $this->translator);
$this->getServer()->getNetwork()->registerInterface($this->interface);
}
} else {
$this->getLogger()->critical("Couldn't find a protocol translator for #" . Info::CURRENT_PROTOCOL . ", disabling plugin");
$this->getPluginLoader()->disablePlugin($this);
}
}
示例2: handle
public function handle($data)
{
$rsa = new RSA();
$rsa->setPrivateKeyFormat(RSA::PRIVATE_FORMAT_XML);
$rsa->setPublicKeyFormat(RSA::PRIVATE_FORMAT_XML);
return ["assignment" => Token::generateNewToken(TOKEN_ASSIGNMENT)->toExternalForm(false)];
}
示例3: calculateSignature
/**
* Static method for quick calls to calculate a signature.
* @link https://developer.walmartapis.com/#authentication
* @param string $consumerId
* @param string $privateKey
* @param string $requestUrl
* @param string $requestMethod
* @param string|null $timestamp
* @return string
* @throws \Exception
*/
public static function calculateSignature($consumerId, $privateKey, $requestUrl, $requestMethod, $timestamp = null)
{
if (is_null($timestamp) || !is_numeric($timestamp)) {
$timestamp = self::getMilliseconds();
}
/**
* Append values into string for signing
*/
$message = $consumerId . "\n" . $requestUrl . "\n" . strtoupper($requestMethod) . "\n" . $timestamp . "\n";
/**
* Get RSA object for signing
*/
$rsa = new RSA();
$decodedPrivateKey = base64_decode($privateKey);
$rsa->setPrivateKeyFormat(RSA::PRIVATE_FORMAT_PKCS8);
$rsa->setPublicKeyFormat(RSA::PRIVATE_FORMAT_PKCS8);
/**
* Load private key
*/
if ($rsa->loadKey($decodedPrivateKey, RSA::PRIVATE_FORMAT_PKCS8)) {
/**
* Make sure we use SHA256 for signing
*/
$rsa->setHash('sha256');
$rsa->setSignatureMode(RSA::SIGNATURE_PKCS1);
$signed = $rsa->sign($message);
/**
* Return Base64 Encode generated signature
*/
return base64_encode($signed);
} else {
throw new \Exception("Unable to load private key", 1446780146);
}
}
示例4: doGenerateKeys
protected static function doGenerateKeys($keySize = 2048)
{
$rsa = new Crypt_RSA();
$rsa->setPrivateKeyFormat(Crypt_RSA::PRIVATE_FORMAT_PKCS1);
$rsa->setPublicKeyFormat(Crypt_RSA::PUBLIC_FORMAT_PKCS1);
defined('CRYPT_RSA_EXPONENT') || define('CRYPT_RSA_EXPONENT', 65537);
defined('CRYPT_RSA_SMALLEST_PRIME') || define('CRYPT_RSA_SMALLEST_PRIME', 64);
return $rsa->createKey($keySize);
}
示例5: onRun
public function onRun()
{
foreach ($this->loadPaths as $name => $path) {
if (!class_exists($name, false) and !interface_exists($name, false)) {
require $path;
}
}
$this->loader->register(true);
$rsa = new RSA();
$this->logger->info("[BigBrother] Generating keypair");
$rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
$rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
$keys = $rsa->createKey(1024);
$this->setResult($keys);
}
示例6: 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();
}
示例7: testPKCS1EncryptionChange
public function testPKCS1EncryptionChange()
{
$rsa = new RSA();
$key = 'PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: phpseclib-generated-key
Public-Lines: 4
AAAAB3NzaC1yc2EAAAADAQABAAAAgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4
eCZ0FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RK
NUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDy
R4e9T04ZZw==
Private-Lines: 8
AAAAgBYo5KOevqhsjfDNEVcmkQF8/vsU6hwS4d7ceFYDLa0PlhIAo4aE8KNtyjAQ
LiRkmJ0ZqAWTN5TH0ynryJAInTxMb2AnZuXWKt106C5JC7+S9qSCFThTAxvihEpw
BVe5dnPnJ80TFtPm+n/JkdQic2bsVSy+kNNn7y4uef5m0mMRAAAAQQDeAw6fiIQX
GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJ
rmfPwIGm63ilAAAAQQDEIvkdBvZtCvgHKitwxab+EQ/YxnNE5XvfIXjWE+xEL2br
oquF470c9Mm6jf/2zmn6yobE6UUvQ0O3hKSiyOAbAAAAQBGoiuSoSjafUhV7i1cE
Gpb88h5NBYZzWXGZ37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ
4p0=
Private-MAC: 03e2cb74e1d67652fbad063d2ed0478f31bdf256
';
$key = preg_replace('#(?<!\\r)\\n#', "\r\n", $key);
$this->assertTrue($rsa->load($key));
PKCS1::setEncryptionAlgorithm('AES-256-CBC');
$rsa->setPassword('demo');
$encryptedKey = (string) $rsa;
$this->assertRegExp('#AES-256-CBC#', $encryptedKey);
$rsa = new RSA();
$rsa->setPassword('demo');
$this->assertTrue($rsa->load($encryptedKey));
$rsa->setPassword();
$rsa->setPrivateKeyFormat('PuTTY');
$key2 = (string) $rsa;
$this->assertSame($key, $key2);
}