hexToBin()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * Private/Public key convertion.
4
 *
5
 * @package ThreemaGateway
6
 * @author rugk
7
 * @copyright Copyright (c) 2015-2016 rugk
8
 * @license MIT
9
 */
10
11
class ThreemaGateway_Handler_Action_KeyConverter extends ThreemaGateway_Handler_Action_Abstract
12
{
13
    /**
14
     * Converts a key from hex to binary format.
15
     *
16
     * It automatically removes the prefixes if necessary.
17
     *
18
     * @param  string $keyHex The key in hex
19
     * @return string
20
     */
21
    public function hexToBin($keyHex)
22
    {
23
        //delete suffix
24
        $keyHex = ThreemaGateway_Helper_Key::removeSuffix($keyHex);
25
26
        return $this->getCryptTool()->hex2bin($keyHex);
27
    }
28
29
    /**
30
     * Converts a key from binary to hex format.
31
     *
32
     * @param  string $keyBin The key in binary format
33
     * @return string
34
     */
35
    public function binToHex($keyBin)
36
    {
37
        return $this->getCryptTool()->bin2hex($keyBin);
38
    }
39
40
    /**
41
     * Converts a key from a private key to a public key version.
42
     *
43
     * @param  string $privateKey The private key in hex
44
     * @return string public key in hex
45
     */
46
    public function derivePublicKey($privateKey)
47
    {
48
        return $this->binToHex($this->getCryptTool()->derivePublicKey($this->hexToBin($privateKey)));
49
    }
50
}
51