Encrypt::__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\MsgApi\Tools\CryptTool;
12
13
/**
14
 * Encrypt the stdin with the given @privateKey for the given @publicKey
15
 * @package Threema\Console\Command
16
 */
17
class Encrypt extends Base {
18
	public function __construct() {
19
		parent::__construct('Encrypt',
20
			array(self::argPrivateKey, self::argPublicKey),
21
			'Encrypt standard input using the given sender private key and recipient public key. two lines to standard output: first the nonce (hex), and then the box (hex).');
22
	}
23
24
	/**
25
	 * run the command
26
	 */
27 View Code Duplication
	protected function doRun() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
		$privateKey = $this->getArgumentPrivateKey(self::argPrivateKey);
29
		$publicKey = $this->getArgumentPublicKey(self::argPublicKey);
30
		$textToEncrypt = $this->readStdIn();
31
		Common::required($privateKey, $publicKey, $textToEncrypt);
32
33
		$cryptTool = CryptTool::getInstance();
34
		//create a random nonce
35
		$newNonce = $cryptTool->randomNonce();
36
		$encryptedMessageText = $cryptTool->encryptMessageText($textToEncrypt, $privateKey, $publicKey, $newNonce);
37
38
		Common::ln($cryptTool->bin2hex($newNonce));
39
		//output encrypted text
40
		Common::ln($cryptTool->bin2hex($encryptedMessageText));
41
	}
42
}
43