PATH:
home
/
thebhoeo
/
.trash
/
backwpup
/
inc
<?php /** * Encrypt / decrypt data using Open SSL. * * This is the method used with PHP 5.3+ and open SSL lib available. * * Normally we should implement an interface, but at the moment with PHP 5.2 and the "poor" autoloader we have, * an interface would just be another file in "/inc" folder causing confusion. Also, I don't want to create an * interface in a file named `class-...php`. When we get rid of PHP 5.2, we setup a better autoloader and we get rid of * WP coding standard, we finally could consider to introduce an interface. */ class BackWPup_Encryption_OpenSSL { /** * Prefix. * * @var string */ public const PREFIX = 'OSSL$'; /** * Cipher Method. * * @var string */ private static $cipher_method; /** * Encryption key. * * @var string */ private $key; /** * Encryption key type. * * @var string */ private $key_type; /** * BackWPup_Encryption_OpenSSL constructor. * * @param string $enc_key Encryption key. * @param string $key_type Key type identifier. */ public function __construct( $enc_key, $key_type ) { $this->key = md5( (string) $enc_key ); $this->key_type = (string) $key_type; } /** * Supported. * * @return bool */ public static function supported() { return function_exists( 'openssl_get_cipher_methods' ) && self::cipher_method(); } /** * Encrypt a string using Open SSL lib with AES-256-CTR cypher. * * @param string $value Value to encrypt. * * @return string Encrypted string. */ public function encrypt( $value ) { if ( ! is_string( $value ) || ! $value ) { return ''; } $nonce = openssl_random_pseudo_bytes( openssl_cipher_iv_length( self::cipher_method() ) ); $openssl_raw_data = defined( 'OPENSSL_RAW_DATA' ) ? OPENSSL_RAW_DATA : 1; $encrypted = openssl_encrypt( $value, self::cipher_method(), $this->key, $openssl_raw_data, $nonce ); return BackWPup_Encryption::PREFIX . self::PREFIX . $this->key_type . base64_encode( $nonce . $encrypted ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Binary-safe encoding. } /** * Decrypt a string using Open SSL lib with AES-256-CTR cypher. * * @param string $value Value to decrypt. * * @return string Decrypted string. */ public function decrypt( $value ) { if ( ! is_string( $value ) || ! $value || 0 !== strpos( $value, BackWPup_Encryption::PREFIX . self::PREFIX . $this->key_type ) ) { return ''; } $no_prefix = substr( $value, strlen( BackWPup_Encryption::PREFIX . self::PREFIX . $this->key_type ) ); $encrypted = base64_decode( $no_prefix, true ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode -- Binary-safe decoding. if ( false === $encrypted ) { return ''; } $nonce_size = openssl_cipher_iv_length( self::cipher_method() ); $nonce = substr( $encrypted, 0, $nonce_size ); $to_decrypt = substr( $encrypted, $nonce_size ); $openssl_raw_data = defined( 'OPENSSL_RAW_DATA' ) ? OPENSSL_RAW_DATA : true; return openssl_decrypt( $to_decrypt, self::cipher_method(), $this->key, $openssl_raw_data, $nonce ); } /** * Cipher Method. * * @return string */ private static function cipher_method() { if ( is_string( self::$cipher_method ) ) { return self::$cipher_method; } $all_methods = openssl_get_cipher_methods(); if ( ! $all_methods ) { self::$cipher_method = ''; return ''; } $preferred = [ 'AES-256-CTR', 'AES-128-CTR', 'AES-192-CTR' ]; foreach ( $preferred as $method ) { if ( in_array( $method, $all_methods, true ) ) { self::$cipher_method = $method; return $method; } } self::$cipher_method = reset( $all_methods ); return self::$cipher_method; } }
[-] class-system-tests-runner.php
[edit]
[-] class-jobtype-dbdump.php
[edit]
[-] class-destination-rsc.php
[edit]
[-] class-encryption.php
[edit]
[-] class-destination-downloader-factory.php
[edit]
[-] class-destination-downloader-interface.php
[edit]
[-] class-destination-ftp-type-ftp.php
[edit]
[-] class-path-fixer.php
[edit]
[-] class-message-box.php
[edit]
[-] class-destination-dropbox-api.php
[edit]
[-] class-option.php
[edit]
[-] class-destination-dropbox-api-request-exception.php
[edit]
[-] class-page-about.php
[edit]
[-] class-migrate.php
[edit]
[-] class-system-requirements.php
[edit]
[-] class-adminbar.php
[edit]
[-] class-msazure-destination-configuration.php
[edit]
[-] class-job.php
[edit]
[-] class-destination-ftp-type-exception.php
[edit]
[-] class-destination-sugarsync-api.php
[edit]
[-] class-download-file-interface.php
[edit]
[-] class-encryption-fallback.php
[edit]
[-] BackWPup.php
[edit]
[-] class-page-backwpup.php
[edit]
[-] class-destination-downloader-data.php
[edit]
[-] class-mysqldump-exception.php
[edit]
[-] class-s3-destination.php
[edit]
[-] class-destination-ftp.php
[edit]
[-] class-cron.php
[edit]
[+]
Notice
[-] class-destination-downloader.php
[edit]
[-] class-destinations.php
[edit]
[-] class-destination-ftp-downloader.php
[edit]
[-] class-destination-dropbox-downloader.php
[edit]
[-] class-download-handler.php
[edit]
[-] class-destination-dropbox.php
[edit]
[-] class-system-tests.php
[edit]
[-] class-destination-folder-downloader.php
[edit]
[-] class-destination-ftp-type.php
[edit]
[-] class-thirdparties.php
[edit]
[-] class-jobtype-wpplugin.php
[edit]
[-] class-directory.php
[edit]
[-] class-recursive-directory.php
[edit]
[-] class-destination-msazure-downloader.php
[edit]
[-] class-destination-connect-interface.php
[edit]
[-] class-install.php
[edit]
[-] class-admin.php
[edit]
[-] class-jobtype-file.php
[edit]
[-] functions.php
[edit]
[+]
Utils
[+]
ThirdParty
[-] class-destination-s3-downloader.php
[edit]
[-] class-destination-rsc-downloader.php
[edit]
[-] class-destination-sugarsync-downloader.php
[edit]
[-] class-destination-email.php
[edit]
[+]
..
[-] class-mysqldump.php
[edit]
[-] class-page-firstbackup.php
[edit]
[-] class-jobtype-wpexp.php
[edit]
[-] class-jobtype-dbcheck.php
[edit]
[-] class-file.php
[edit]
[-] class-sanitize-path.php
[edit]
[+]
Settings
[-] class-destination-s3.php
[edit]
[-] class-page-logs.php
[edit]
[-] class-factory-exception.php
[edit]
[-] class-page-restore.php
[edit]
[+]
dependencies
[-] class-create-archive-exception.php
[edit]
[-] class-page-editjob.php
[edit]
[-] class-page-backups.php
[edit]
[-] class-destination-dropbox-api-exception.php
[edit]
[-] class-create-archive.php
[edit]
[-] class-encryption-openssl.php
[edit]
[-] class-destination-onedrive-config-trait.php
[edit]
[-] class-destination-download-exception.php
[edit]
[-] class-download-file.php
[edit]
[-] class-page-settings.php
[edit]
[-] class-destination-msazure.php
[edit]
[-] class-page-onboarding.php
[edit]
[-] class-destination-folder.php
[edit]
[-] class-jobtypes.php
[edit]
[-] class-destination-connect-exception.php
[edit]
[-] class-destination-sugarsync.php
[edit]
[-] class-page-jobs.php
[edit]
[-] class-destination-sugarsync-api-exception.php
[edit]
[-] class-encryption-mcrypt.php
[edit]