GenerateKeyPair::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @author Threema GmbH
4
 * @copyright Copyright (c) 2015-2016 Threema GmbH
5
 */
6
7
8
namespace Threema\Console\Command;
9
10
use Threema\Console\Common;
11
use Threema\Console\Command\CryptTool;
12
13
class GenerateKeyPair extends Base {
14
	public function __construct() {
15
		parent::__construct('Generate Key Pair',
16
			array(self::argPrivateKeyFile, self::argPublicKeyFile),
17
			'Generate a new key pair and write the private and public keys to the respective files (in hex).');
18
	}
19
20
	protected function doRun() {
21
		$cryptTool = CryptTool::getInstance();
22
		$keyPair = $cryptTool->generateKeyPair();
23
24
		$privateKeyHex = $cryptTool->bin2hex($keyPair->privateKey);
25
		$publicKeyHex = $cryptTool->bin2hex($keyPair->publicKey);
26
27
		file_put_contents($this->getArgument(self::argPrivateKeyFile), Common::convertPrivateKey($privateKeyHex)."\n");
28
		file_put_contents($this->getArgument(self::argPublicKeyFile), Common::convertPublicKey($publicKeyHex)."\n");
29
30
		Common::l('key pair generated');
31
	}
32
}
33