/** * @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'])); }
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)); } }
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']); }
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']); }
function generateAndAdd() { $rsa = new \Crypt_RSA(); $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH); $this->set($rsa->createKey()); $this->save(); }
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']); }
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']); }
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; }
/** * 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); }
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']); }
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']); }
/** * 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']; }
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; }
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; }
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)); }
public function testGeneratedKey() { $publickey = null; $privatekey = null; $rsa = new Crypt_RSA(); extract($rsa->createKey(512)); /* 128, 256 didn't work, 512, 1024 work, 2048 didn't finish in 5 min. */ $rsa->loadKey($publickey, CRYPT_RSA_PRIVATE_FORMAT_PKCS1); // echo "privatekey=",$privatekey,"\n"; // echo "publickey=",$publickey,"\n"; $str = "123"; $enc = $rsa->encrypt($str); // echo "encoded=",$enc,"\n"; $rsa->loadKey($privatekey, CRYPT_RSA_PRIVATE_FORMAT_PKCS1); $dec = $rsa->decrypt($enc); $this->assertEquals($str, $dec, "Basic Encrypt/Decrypt with Generated Key"); }
public function generateKeyPair($keyPath, $keySize = 1024) { $privKey = new \Crypt_RSA(); extract($privKey->createKey($keySize)); $privKey->loadKey($privatekey); $pubKey = new \Crypt_RSA(); $pubKey->loadKey($publickey); $pubKey->setPublicKey(); $subject = new \File_X509(); $subject->setDNProp('id-of-organization', 'phpseclib demo cert'); $subject->setPublicKey($pubKey); $issuer = new \File_X509(); $issuer->setPrivateKey($privKey); $issuer->setDN($subject->getDN()); $x509 = new \File_X509(); $result = $x509->sign($issuer, $subject); file_put_contents($keyPath . '/private.key', $privKey->getPrivateKey()); file_put_contents($keyPath . '/public.crt', $x509->saveX509($result)); }
function generate_key_pair() { set_include_path(get_include_path() . PATH_SEPARATOR . S3DB_SERVER_ROOT . '/pearlib/phpseclib'); if (is_file(S3DB_SERVER_ROOT . '/pearlib/phpseclib/Crypt/RSA.php')) { include S3DB_SERVER_ROOT . '/pearlib/phpseclib/Crypt/RSA.php'; define('CRYPT_RSA_SMALLEST_PRIME', 1000); $rsa = new Crypt_RSA(); $createKey = $rsa->createKey(10 * 64); $keys = array('public' => base64_encode($createKey['publickey']), 'private' => $createKey['privatekey']); } else { require_once S3DB_SERVER_ROOT . '/pearlib/RSACrypt/RSA.php'; $key_length = '64'; $key_pair = new Crypt_RSA_KeyPair($key_length); check_error($key_pair); $public_key = $key_pair->getPublicKey(); $private_key = $key_pair->getPrivateKey(); $keys = array('public' => $public_key->toString(), 'private' => $private_key->toString()); } return $keys; }
public function createPrivateKey($sslCnfPath) { $rsa = new Crypt_RSA(); $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1); # We hebben deze code geconfigureerd uit Crypt/RSA.php omdat # we anders de configuratie parameter niet mee kunnen geven aan # openssl_pkey_new() if (CRYPT_RSA_MODE != CRYPT_RSA_MODE_OPENSSL) { # We krijgen de keys base encoded terug $keyPair = $rsa->createKey(); return array('public' => $keyPair['publickey'], 'private' => $keyPair['privatekey']); } else { $opensslPrivKey = openssl_pkey_new(array('private_key_bits' => 1024, 'config' => $sslCnfPath)); openssl_pkey_export($opensslPrivKey, $privateKey, null, array('config' => $sslCnfPath)); $publicKey = openssl_pkey_get_details($opensslPrivKey); $publicKey = $publicKey['key']; openssl_free_key($opensslPrivKey); return array('public' => $publicKey, 'private' => $privateKey); } # else }
/** * @return array * Array with elements: * - privatekey: string. * - publickey: string. */ public static function create() { $rsa = new \Crypt_RSA(); return $rsa->createKey(Constants::RSA_KEYLEN); }
public function generate_new_keypair() { $this->ensure_crypto_loaded(); $rsa = new Crypt_RSA(); $keys = $rsa->createKey(2048); if (empty($keys['privatekey'])) { $this->set_key_local(false); } else { $this->set_key_local($keys['privatekey']); } if (empty($keys['publickey'])) { $this->set_key_remote(false); } else { $this->set_key_remote($keys['publickey']); } return empty($keys['publickey']) ? false : true; }
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; }
<?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); }
set_time_limit(300); //require_once( ABSPATH . 'includes/errors.php' ); require_once ABSPATH . 'db_config.php'; require_once ABSPATH . 'includes/autoload.php'; $db = new MySQLidb(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, DB_PORT); $param = array(); $param['nopass']['x'] = 176; $param['nopass']['y'] = 100; $param['nopass']['width'] = 100; $param['nopass']['bg_path'] = ABSPATH . 'img/k_bg.png'; $param['pass']['x'] = 167; $param['pass']['y'] = 93; $param['pass']['width'] = 118; $param['pass']['bg_path'] = ABSPATH . 'img/k_bg_pass.png'; $rsa = new Crypt_RSA(); extract($rsa->createKey(2048)); $publickey = clear_public_key($publickey); $priv = $rsa->_parseKey($privatekey, CRYPT_RSA_PRIVATE_FORMAT_PKCS1); if (!empty($_REQUEST['password'])) { $aes = new Crypt_AES(CRYPT_AES_MODE_ECB); $aes->setKey(md5($_REQUEST['password'])); $text = $privatekey; $aes_encr = $aes->encrypt($text); $private_key = chunk_split(base64_encode($aes_encr), 64); $param = $param['pass']; $k_bg_path = ABSPATH . 'img/k_bg.png'; } else { $private_key = str_replace(array('-----BEGIN RSA PRIVATE KEY-----', '-----END RSA PRIVATE KEY-----'), '', $privatekey); $param = $param['nopass']; } $iPod = stripos($_SERVER['HTTP_USER_AGENT'], "iPod");
protected function generateKeyPair() { include dirname(__FILE__) . '/phpseclib/Crypt/RSA.php'; $rsa = new Crypt_RSA(); extract($rsa->createKey(2048)); // Override POST data $_POST['TRUSTLY_MERCHANT_PRIVATE_KEY'] = trim($privatekey); $_POST['TRUSTLY_MERCHANT_PUBLIC_KEY'] = trim($publickey); Configuration::updateValue('TRUSTLY_MERCHANT_PRIVATE_KEY', $_POST['TRUSTLY_MERCHANT_PRIVATE_KEY']); Configuration::updateValue('TRUSTLY_MERCHANT_PUBLIC_KEY', $_POST['TRUSTLY_MERCHANT_PUBLIC_KEY']); return true; }
/** * Generate a new keypair for a local user and store in the database. * * Warning: this can be very slow on systems without the GMP module. * Runtimes of 20-30 seconds are not unheard-of. * * @param int $user_id id of local user we're creating a key for */ public function generate($user_id) { $rsa = new Crypt_RSA(); $keypair = $rsa->createKey(); $rsa->loadKey($keypair['privatekey']); $this->privateKey = new Crypt_RSA(); $this->privateKey->loadKey($keypair['privatekey']); $this->publicKey = new Crypt_RSA(); $this->publicKey->loadKey($keypair['publickey']); $this->user_id = $user_id; $this->insert(); }
} else { openssl_pkey_export($res, $privKey); openssl_pkey_export_to_file($res, 'privKey'); $pubKey = openssl_pkey_get_details($res); $pubKey = $pubKey['key']; $pubKeyFile = fopen('pubKey', "w"); fwrite($pubKeyFile, $pubKey); fclose($pubKeyFile); } */ require_once 'Crypt/RSA.php'; require_once 'Crypt/ECDSA.php'; $rsa = new Crypt_RSA(); extract($rsa->createKey(2048)); $privKey = fopen('privKey.lic', "w"); fwrite($privKey, $privatekey); fclose($privKey); $pubKey = fopen('pubKey.lic', "w"); fwrite($pubKey, $publickey); fclose($pubKey); unset($rsa); $rsa = new Crypt_RSA(); extract($rsa->createKey(4096)); $privKey = fopen('privKey.sign', "w"); fwrite($privKey, $privatekey); fclose($privKey); $pubKey = fopen('pubKey.sign', "w"); fwrite($pubKey, $publickey); fclose($pubKey); unset($rsa);
} 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/ !'); } //---------------------------------------------------------+ // Creating Database Schema
function generate_new_keys() { require_once 'RSA.php'; $rsa = new Crypt_RSA(); extract($rsa->createKey(1536)); if (empty($privatekey) == FALSE && empty($publickey) == FALSE) { $symbols = array("\r"); $new_publickey = str_replace($symbols, "", $publickey); $new_privatekey = str_replace($symbols, "", $privatekey); $sql = "UPDATE `my_keys` SET `field_data` = '{$new_privatekey}' WHERE `my_keys`.`field_name` = 'server_private_key' LIMIT 1"; if (mysql_query($sql) == TRUE) { // Private Key Update Success $sql = "UPDATE `my_keys` SET `field_data` = '{$new_publickey}' WHERE `my_keys`.`field_name` = 'server_public_key' LIMIT 1"; if (mysql_query($sql) == TRUE) { // Blank reverse crypto data field mysql_query("UPDATE `options` SET `field_data` = '' WHERE `options`.`field_name` = 'generation_key_crypt' LIMIT 1"); // Public Key Update Success return 1; } } } else { // Key Pair Creation Error return 0; } return 0; }
'); $row = $db->fetchArray($res); if (!$row['video_url_id']) { $row['video_url_id'] = 'null'; } if (!$row['video_type']) { $row['video_type'] = 'null'; } $tpl['data'] = $row; $tpl['data']['type'] = 'new_miner'; $tpl['data']['type_id'] = ParseData::findType($tpl['data']['type']); $tpl['data']['time'] = time(); $tpl['data']['user_id'] = $user_id; $tpl['data']['face_hash'] = hash('sha256', hash_file('sha256', ABSPATH . 'public/' . $_SESSION['user_id'] . '_user_face.jpg')); $tpl['data']['profile_hash'] = hash('sha256', hash_file('sha256', ABSPATH . 'public/' . $_SESSION['user_id'] . '_user_profile.jpg')); $x = explode(', ', $tpl['data']['geolocation']); $tpl['data']['latitude'] = $x[0]; $tpl['data']['longitude'] = $x[1]; // проверим, есть ли не обработанные ключи в локальной табле $node_public_key = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\tSELECT `public_key`\n\t\tFROM `" . DB_PREFIX . MY_PREFIX . "my_node_keys`\n\t\tWHERE `block_id` = 0\n\t\t", 'fetch_one'); if (!$node_public_key) { // сгенерим ключ для нода $rsa = new Crypt_RSA(); extract($rsa->createKey(1024)); $publickey = clear_public_key($publickey); $tpl['data']['node_public_key'] = $publickey; $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\tINSERT INTO `" . DB_PREFIX . MY_PREFIX . "my_node_keys` (\n\t\t\t\t`public_key`,\n\t\t\t\t`private_key`\n\t\t\t)\n\t\t\tVALUES (\n\t\t\t\t0x{$publickey},\n\t\t\t\t'{$privatekey}'\n\t\t\t)"); } else { list(, $tpl['data']['node_public_key']) = unpack("H*", $node_public_key); } require_once ABSPATH . 'templates/upgrade_7.tpl';