WC_GZD_Gateway_Direct_Debit_Encryption_Helper

The WooCommerce Germanized WC GZD Gateway Direct Debit Encryption Helper class.

Defined (1)

The class is defined in the following location(s).

/includes/gateways/direct-debit/class-wc-gzd-gateway-direct-debit-encryption-helper.php  
  1. class WC_GZD_Gateway_Direct_Debit_Encryption_Helper { 
  2.  
  3. protected static $_instance = null; 
  4.  
  5. public static function instance() { 
  6. if ( is_null( self::$_instance ) ) 
  7. self::$_instance = new self(); 
  8. return self::$_instance; 
  9.  
  10. private function __construct() { 
  11. // Make sure that random_int exists 
  12. if ( ! function_exists( 'random_int' ) ) { 
  13. require_once ABSPATH . WPINC . '/random_compat/random.php'; 
  14.  
  15. public function get_random_key() { 
  16. $key = Crypto\Key::createNewRandomKey(); 
  17. return $key->saveToAsciiSafeString(); 
  18.  
  19. public function is_configured() { 
  20. return ( $this->get_key() ? true : false ); 
  21.  
  22. public function encrypt( $string ) { 
  23. if ( empty( $string ) ) 
  24. return $string; 
  25.  
  26. return Crypto\Crypto::encrypt( $string, $this->get_key() ); 
  27.  
  28. public function decrypt( $string ) { 
  29. if ( empty( $string ) ) 
  30. return $string; 
  31.  
  32. $secret_data = $string; 
  33.  
  34. try { 
  35. $secret_data = Crypto\Crypto::decrypt( $string, $this->get_key() ); 
  36. } catch (Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { 
  37.  
  38.  
  39. return $secret_data; 
  40.  
  41. private function get_key() {  
  42. if ( defined( 'WC_GZD_DIRECT_DEBIT_KEY' ) ) 
  43. return Crypto\Key::loadFromAsciiSafeString( WC_GZD_DIRECT_DEBIT_KEY ); 
  44. return false; 
  45.