Beispiel #1
0
 public static function generate($options = array(), $dataStore = null)
 {
     $bits = isset($options['size']) ? $options['size'] : 4096;
     $key = openssl_pkey_new(array('digest_alg' => 'sha1', 'private_key_bits' => $bits, 'private_key_type' => OPENSSL_KEYTYPE_RSA));
     if (!openssl_pkey_export($key, $privateKeyPem)) {
         throw new Exception("openssl_pkey_export failed with no explanation");
     }
     $privateKeyDer = TOGoS_RSAUtil_Util::pemToDer($privateKeyPem);
     $det = openssl_pkey_get_details($key);
     /** PEM-formatted public key */
     $publicKeyPem = $det['key'];
     $publicKeyDer = TOGoS_RSAUtil_Util::pemToDer($publicKeyPem);
     if ($dataStore !== null) {
         $dataStore->store($publicKeyDer);
     }
     return self::create2($privateKeyDer, $publicKeyDer);
 }