· 7 years ago · Apr 08, 2018, 10:12 PM
1<?php
2/**
3 * @package Joomla.Cli
4 *
5 * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
6 * @license GNU General Public License version 2 or later; see LICENSE.txt
7 */
8
9/**
10 * This is a CLI script to generate keypairs which should be called from the command-line, not the
11 * web. For example something like:
12 * /usr/bin/php /path/to/site/cli/genkeypairs.php
13 */
14
15// Initialize Joomla framework
16const _JEXEC = 1;
17
18// Load system defines
19if (file_exists(dirname(__DIR__) . '/defines.php'))
20{
21 require_once dirname(__DIR__) . '/defines.php';
22}
23
24if (!defined('_JDEFINES'))
25{
26 define('JPATH_BASE', dirname(__DIR__));
27 require_once JPATH_BASE . '/includes/defines.php';
28}
29
30// Get the framework.
31require_once JPATH_LIBRARIES . '/import.legacy.php';
32
33// Bootstrap the CMS libraries.
34require_once JPATH_LIBRARIES . '/cms.php';
35
36/**
37 * CLI script to generate keypairs.
38 *
39 * @since __DEPLOY_VERSION__
40 */
41class genkeys extends JApplicationCli
42{
43 /**
44 * Entry point for the script
45 *
46 * @return void
47 *
48 * @since __DEPLOY_VERSION__
49 */
50 public function doExecute()
51 {
52 // Keypairs generation
53 $alikon_kp = ParagonIE_Sodium_Compat::crypto_sign_keypair();
54 $alikon_sk = ParagonIE_Sodium_Compat::crypto_sign_secretkey($alikon_kp);
55 $alikon_pk = ParagonIE_Sodium_Compat::crypto_sign_publickey($alikon_kp);
56 // Show the keypairs
57 $secret_key = ParagonIE_Sodium_Compat::bin2hex($alikon_sk);
58 $public_key = ParagonIE_Sodium_Compat::bin2hex($alikon_pk);
59
60 echo 'PublicKey:' . $public_key, PHP_EOL;
61 echo '---', PHP_EOL;
62 echo 'SecrectKey:' . $secret_key, PHP_EOL;
63 }
64}
65
66JApplicationCli::getInstance('genkeys')->execute();