dbXapp
2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Toggle main menu visibility
Loading...
Searching...
No Matches
dbxCrypt.class.php
Go to the documentation of this file.
1
<?php
2
3
class
dbxCrypt
{
4
private
$encryptionKey;
5
private
$iv;
6
7
function
__construct
($encryptionKey) {
8
// Initialization vector for encryption (16 bytes for AES-128, 24 bytes for AES-192, 32 bytes for AES-256)
9
$this->iv = openssl_random_pseudo_bytes(16);
10
$this->encryptionKey = $encryptionKey;
11
}
12
13
function
encryptValue
($value) {
14
$encryptedValue = openssl_encrypt($value,
'aes-256-cbc'
, $this->encryptionKey, 0, $this->iv);
15
// Combine IV and encrypted value for storage (IV should be unique for each encryption)
16
return
base64_encode($this->iv . $encryptedValue);
17
}
18
19
function
decryptValue
($encryptedValue) {
20
// Separate IV and encrypted value
21
$data = base64_decode($encryptedValue);
22
$iv = substr($data, 0, 16);
23
$encryptedData = substr($data, 16);
24
// Decrypt using the IV and encryption key
25
return
openssl_decrypt($encryptedData,
'aes-256-cbc'
, $this->encryptionKey, 0, $iv);
26
}
27
}
28
29
/*
30
// Example usage
31
$encryptionKey = "YourEncryptionKey";
32
$helper = new EncryptionHelper($encryptionKey);
33
34
// Encrypt a value
35
$originalValue = "SensitiveData";
36
$encryptedValue = $helper->encryptValue($originalValue);
37
echo "Encrypted Value: " . $encryptedValue . PHP_EOL;
38
39
// Decrypt the encrypted value
40
$decryptedValue = $helper->decryptValue($encryptedValue);
41
echo "Decrypted Value: " . $decryptedValue . PHP_EOL;
42
*/
43
44
45
?>
dbxCrypt
Definition
dbxCrypt.class.php:3
dbxCrypt\encryptValue
encryptValue($value)
Definition
dbxCrypt.class.php:13
dbxCrypt\decryptValue
decryptValue($encryptedValue)
Definition
dbxCrypt.class.php:19
dbxCrypt\__construct
__construct($encryptionKey)
Definition
dbxCrypt.class.php:7
dbx
include
dbxCrypt.class.php
Generated by
1.17.0