PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 7.1
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v7.1
7.13 7.12 trunk 1.1 2.1.1 5.9 6.0 6.1 6.10 6.11 6.12 6.12.1 6.2 6.3 6.4 6.5 6.5.1 6.6 6.7 6.8 6.9 7.0 7.0.1 7.1 7.10 All 34 releases
wp-database-backup / includes / class-symmetric-encryption.php

class-symmetric-encryption.php in WP Database Backup – Unlimited Database & Files Backup by Backup for WP 7.1, at includes/class-symmetric-encryption.php

46 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class SymmetricEncryption {
4
5 private $cipher;
6
7 public function __construct($cipher = 'aes-256-cbc') {
8 $this->cipher = $cipher;
9 }
10
11 private function getKeySize() {
12 if (preg_match("/([0-9]+)/i", $this->cipher, $matches)) {
13 return $matches[1] >> 3;
14 }
15 return 0;
16 }
17
18 private function derived($password, $salt) {
19
20 $AESKeyLength = $this->getKeySize();
21 $AESIVLength = openssl_cipher_iv_length($this->cipher);
22
23 $pbkdf2 = hash_pbkdf2("SHA1", $password, mb_convert_encoding($salt, 'UTF-16LE'), 1000, $AESKeyLength + $AESIVLength, TRUE);
24
25 $key = substr($pbkdf2, 0, $AESKeyLength);
26 $iv = substr($pbkdf2, $AESKeyLength, $AESIVLength);
27
28 $derived = new stdClass();
29 $derived->key = $key;
30 $derived->iv = $iv;
31 return $derived;
32 }
33
34 function encrypt($message, $password, $salt) {
35 $derived = $this->derived($password, $salt);
36 $enc = openssl_encrypt(mb_convert_encoding($message, 'UTF-16', 'UTF-8'), $this->cipher, $derived->key, 0, $derived->iv);
37 return '$$'.$enc.'$$';
38 }
39
40 function decrypt($message, $password, $salt) {
41 $derived = $this->derived($password, $salt);
42 $dec = openssl_decrypt($message, $this->cipher, $derived->key, 0, $derived->iv);
43 return mb_convert_encoding($dec, 'UTF-8', 'UTF-16');
44 }
45
46 }