Repository navigation
Expand file tree
/
Copy pathDecryptionManager.php
More file actions
74 lines (57 loc) · 2.02 KB
/
Copy pathDecryptionManager.php
File metadata and controls
74 lines (57 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* Class DecryptionManager
* Class to handle the decryption process for the encrypted credentials array.
* Array contains "username" and "password" to the database.
* Must have the 'Key', 'IV', and arrayEncrypt.txt created, and must be place in the parent directory
* of this PHP file.
* @see [encrypt.php]
*
*/
class DecryptionManager {
/**
* Function to get the Key Value stored in the 'Key' file.
* Must be in parent directory.
* @return false|string
*/
private function getKey(){
$keyFile = fopen("../Key", "r") or die("Could not open key file");
$key = fgets($keyFile);
fclose($keyFile);
return $key;
}
/**
* Function to get the IV Value stored in the 'IV' file.
* Must be in parent directory.
* @return false|string
*/
private function getIV(){
$ivFile = fopen("../IV", "r") or die("Could not open IV file");
$iv = fgets($ivFile);
fclose($ivFile);
return $iv;
}
/**
* Function that will decrypt the serialized credential array in
* arrayEncrypt.txt and deserialize it so it can be used in
* @see getDB()
* @return array : credential array containing the credentials for the database.
* @example credentialArray["username"] = user name for the database.
* @example credentialArray["password"] = password for the database.
*/
//TODO if not up on directory, get rid of ../
function getCredentialArray(): array
{
$myFile = fopen("../arrayEncrypt.txt", "r") or die("Cannot get credential array file");
$decrypt = fgets($myFile);
fclose($myFile);
$cipher = "aes-128-ctr";
// Use OpenSSl Encryption method
$options = 0;
// Non-NULL Initialization Vector for encryption
$encryption_iv = $this->getIV();
// Store the encryption key
$encryption_key = $this->getKey();
return unserialize(openssl_decrypt($decrypt, $cipher, $encryption_key, $options, $encryption_iv));
}
}