Skip to content

Instantly share code, notes, and snippets.

@alikon
Created March 31, 2018 11:20
Show Gist options
  • Save alikon/db3356e8bdcc3c23968cec1179870302 to your computer and use it in GitHub Desktop.
Save alikon/db3356e8bdcc3c23968cec1179870302 to your computer and use it in GitHub Desktop.
<?php
/**
* @package Joomla.Cli
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
/**
* This is a CLI script to generate keypairs which should be called from the command-line, not the
* web. For example something like:
* /usr/bin/php /path/to/site/cli/genkeypairs.php
*/
// Initialize Joomla framework
const _JEXEC = 1;
// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}
// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';
// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';
/**
* CLI script to generate keypairs.
*
* @since __DEPLOY_VERSION__
*/
class genkeys extends JApplicationCli
{
/**
* Entry point for the script
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function doExecute()
{
// Keypairs generation
$alikon_kp = ParagonIE_Sodium_Compat::crypto_sign_keypair();
$alikon_sk = ParagonIE_Sodium_Compat::crypto_sign_secretkey($alikon_kp);
$alikon_pk = ParagonIE_Sodium_Compat::crypto_sign_publickey($alikon_kp);
// Show the keypairs
$secret_key = ParagonIE_Sodium_Compat::bin2hex($alikon_sk);
$public_key = ParagonIE_Sodium_Compat::bin2hex($alikon_pk);
echo 'PublicKey:' . $public_key, PHP_EOL;
echo '---', PHP_EOL;
echo 'SecrectKey:' . $secret_key, PHP_EOL;
}
}
JApplicationCli::getInstance('genkeys')->execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment