Code Duplication    Length = 14-15 lines in 2 locations

source/Threema/Console/Command/Decrypt.php 1 location

@@ 20-33 (lines=14) @@
17
			'Decrypt standard input using the given recipient private key and sender public key. The nonce must be given on the command line, and the box (hex) on standard input. Prints the decrypted message to standard output.');
18
	}
19
20
	protected function doRun() {
21
		$cryptTool = CryptTool::getInstance();
22
23
		$privateKey = $this->getArgumentPrivateKey(self::argPrivateKey);
24
		$publicKey = $this->getArgumentPublicKey(self::argPublicKey);
25
		$nonce = $cryptTool->hex2bin($this->getArgument(self::argNonce));
26
		$input = $cryptTool->hex2bin($this->readStdIn());
27
28
		Common::required($privateKey, $publicKey, $nonce, $input);
29
		$cryptTool = CryptTool::getInstance();
30
		$message = $cryptTool->decryptMessage($input, $privateKey, $publicKey, $nonce);
31
32
		Common::l((String)$message);
33
	}
34
}
35

source/Threema/Console/Command/Encrypt.php 1 location

@@ 27-41 (lines=15) @@
24
	/**
25
	 * run the command
26
	 */
27
	protected function doRun() {
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