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); } }
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)]; }
/** * Generate a keypair * * @return array ['privatekey' => $privateKey, 'publickey' => $publicKey] */ public function createKey() { $rsa = new RSACrypt(); $rsa->setPublicKeyFormat(RSACrypt::PUBLIC_FORMAT_OPENSSH); $rsa->setPassword($this->config->getSystemValue('secret', '')); return $rsa->createKey(self::CREATE_KEY_BITS); }
/** * 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); } }
public static function generateKeyPair($comment = 'dogpro') { $rsa = new RSA(); $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH); $rsa->setComment($comment); return $rsa->createKey(); }
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); }
private function generateSshKeys() { $rsa = new RSA(); $rsa->setPublicKeyFormat(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; }
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); }
/** * Generates a new key pair. Then stores the private key and returns the public key. * * @param int $keylength Desired key length in bits * @return array The public key as an associative array containing its exponent "e" * and modulus "n" in hexadecimal representation. */ public static function generateKeys($keylength) { $rsa = new RSA(); $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_RAW); $keys = $rsa->createKey($keylength); static::deletePrivateKeyTable(); // delete, if exists - future-proofing for layout changes static::createPrivateKeyTable(); // create, if doesn't exist static::storePrivateKey($keys['privatekey']); $e = new BigInteger($keys['publickey']['e'], 10); $n = new BigInteger($keys['publickey']['n'], 10); $e = $e->toHex(); $n = $n->toHex(); $publickey = array('e' => $e, 'n' => $n); static::writePublicKeyJS($publickey); return $publickey; }
protected function createRSA() { $rsa = new RSA(); $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH); $rsa->setComment($this->config['routerboard']['backupuser'] . "@backup"); $key = $rsa->createKey(2048); if (!empty($key)) { // be safe $this->backupExistRSA(); // create id_rsa.pub (public key) $this->fsys->dumpFile($this->config['system']['ssh-dir'] . DIRECTORY_SEPARATOR . 'id_rsa.pub', $key['publickey']); // create id_rsa (private key) $this->fsys->dumpFile($this->config['system']['ssh-dir'] . DIRECTORY_SEPARATOR . 'id_rsa', $key['privatekey']); // set permissions -rw------- $this->fsys->chmod($this->config['system']['ssh-dir'] . DIRECTORY_SEPARATOR . 'id_rsa', 0600); $this->fsys->chmod($this->config['system']['ssh-dir'] . DIRECTORY_SEPARATOR . 'id_rsa.pub', 0600); // backup existing RSA files for sure. $this->backupExistRSA('routerboard-backup'); $this->logger->log("The SSH-RSA public key has been created. Never delete those files! (id_rsa,id_rsa.pub)", $this->logger->setNotice()); return; } throw new Exception(get_class($this) . " can not create the ssh-rsa public key file!"); }
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(); }
public function getPair() { $installationUuid = $this->name; $publicKeyName = $this->getPublicKeyPath(); $privateKeyName = $this->getPrivateKeyPath(); if (Storage::exists($publicKeyName) === false || Storage::exists($privateKeyName) === false) { $rsa = new RSA(); $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH); $rsa->setComment('*****@*****.**'); $keys = $rsa->createKey(2048); $privateKey = $keys['privatekey']; $publicKey = $keys['publickey']; Storage::disk('local')->put($privateKeyName, $privateKey); Storage::disk('local')->put($publicKeyName, $publicKey); } return ['public' => $publicKeyName, 'private' => $privateKeyName]; /*$sshConnection = ssh2_connect('mycloud.smellynose.com', 22, array('hostkey'=>'ssh-rsa')); $sshSuccess = ssh2_auth_pubkey_file( $sshConnection, 'ahindle', storage_path('app/' . $publicKeyName), storage_path('app/' . $privateKeyName) );*/ }
/** * Regenerate and return the private and public keys for a user * * @author salvipascual * @param String $email * @return Array(privatekey, publickey) * */ public function recreateRSAKeys($email) { // create the public and private keys $rsa = new RSA(); $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH); $keys = $rsa->createKey(); $privatekey = $keys['privatekey']; $publickey = $keys['publickey']; // update the new keys or create a new pair $connection = new Connection(); $connection->deepQuery("INSERT INTO `keys` (email, privatekey, publickey) VALUES('{$email}', '{$privatekey}', '{$publickey}') ON DUPLICATE KEY UPDATE privatekey='{$privatekey}', publickey='{$publickey}', last_usage=CURRENT_TIMESTAMP"); // return the new keys return array("privatekey" => $privatekey, "publickey" => $publickey); }
public function testRawKey() { $rsa = new RSA(); $key = array('e' => new BigInteger('10001', 16), 'n' => new BigInteger('aa18aba43b50deef38598faf87d2ab634e4571c130a9bca7b878267414faab8b471bd8965f5c9fc3' . '818485eaf529c26246f3055064a8de19c8c338be5496cbaeb059dc0b358143b44a35449eb2641131' . '21a455bd7fde3fac919e94b56fb9bb4f651cdb23ead439d6cd523eb08191e75b35fd13a7419b3090' . 'f24787bd4f4e1967', 16)); $this->assertTrue($rsa->load($key)); $rsa->setPublicKeyFormat('raw'); $this->assertEmpty("{$rsa}"); }