Skip to content

Instantly share code, notes, and snippets.

@tubalmartin
Created February 14, 2013 02:36
Show Gist options
  • Save tubalmartin/4950192 to your computer and use it in GitHub Desktop.
Save tubalmartin/4950192 to your computer and use it in GitHub Desktop.
PHPSecLib RSA KEY GENERATOR
<?php
header("Content-type: text/html; charset=UTF-8");
$nl = '<br>';
// http://bestmike007.com/2011/08/secure-data-transmission-between-pure-php-and-javascript-using-rsa/
// Include Library
require_once(dirname(__FILE__) . '/../application/libraries/phpseclib-0.3.1/Crypt/RSA.php');
define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);
$rsa = new Crypt_RSA();
$rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_RAW);
$key = $rsa->createKey(512);
echo '<pre><code>';
echo $key['privatekey'];
echo '</code></pre>';
echo $nl;
$e = new Math_BigInteger($key['publickey']['e'], 10);
$n = new Math_BigInteger($key['publickey']['n'], 10);
echo "Public Key:".$nl;
echo '<pre><code>';
echo $e->toHex();
echo '</code></pre>';
echo $nl;
echo '<pre><code>';
echo $n->toHex();
echo '</code></pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment