Completed
Push — master ( ee148f...3aab2e )
by Michael
02:37
created

AesCtr::decrypt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
/**
4
 * AesCtr.php
5
 * 
6
 * PHP version 5
7
 * 
8
 * @category Dcrypt
9
 * @package  Dcrypt
10
 * @author   Michael Meyer (mmeyer2k) <[email protected]>
11
 * @license  http://opensource.org/licenses/MIT The MIT License (MIT)
12
 * @link     https://github.com/mmeyer2k/dcrypt
13
 */
14
15
namespace Dcrypt;
16
17
/**
18
 * Symmetric AES-256-CTR encryption functions powered by OpenSSL.
19
 * 
20
 * @category Dcrypt
21
 * @package  Dcrypt
22
 * @author   Michael Meyer (mmeyer2k) <[email protected]>
23
 * @license  http://opensource.org/licenses/MIT The MIT License (MIT)
24
 * @link     https://github.com/mmeyer2k/dcrypt
25
 * @link     https://apigen.ci/github/mmeyer2k/dcrypt/namespace-Dcrypt.html
26
 */
27
class AesCtr extends Aes
28
{
29
30
    /**
31
     * AES-256 cipher identifier that will be passed to openssl
32
     * 
33
     * @var string
34
     */
35
    const CIPHER = 'aes-256-ctr';
36
37
    /**
38
     * Decrypt cyphertext
39
     * 
40
     * @param string $cyphertext Cyphertext to decrypt
41
     * @param string $password   Password that should be used to decrypt input data
42
     * @param int    $cost       Number of HMAC iterations to perform on key
43
     * 
44
     * @return string|boolean Returns false on checksum validation failure
45
     */
46
    public static function decrypt($cyphertext, $password, $cost = 0)
47
    {
48
        return Pkcs7::unpad(parent::decrypt($cyphertext, $password, $cost));
49
    }
50
51
    /**
52
     * Encrypt plaintext
53
     * 
54
     * @param string $plaintext Plaintext string to encrypt.
55
     * @param string $password  Password used to encrypt data.
56
     * @param int    $cost      Number of HMAC iterations to perform on key
57
     * 
58
     * @return string 
59
     */
60
    public static function encrypt($plaintext, $password, $cost = 0)
61
    {
62
        return parent::encrypt(Pkcs7::pad($plaintext, 16), $password, $cost);
63
    }
64
65
}
66