Browse Source

Attempt to fix when there are bad encryption methods

Nathaniel van Diepen 6 years ago
parent
commit
96ccdd83ed
1 changed files with 7 additions and 5 deletions
  1. 7 5
      Data/securestring.class.php

+ 7 - 5
Data/securestring.class.php

@@ -12,11 +12,13 @@
 			$methods = Encryption::methods();
 			do{
 				$method = $methods[random_int(0, count($methods) - 1)];
-				$this->encryption = Encryption::from($method);
-				$ivlen = $this->encryption->iv_len();
-				$this->password = openssl_random_pseudo_bytes($ivlen);
-				$this->iv = openssl_random_pseudo_bytes($ivlen);
-				$this->data = $this->encryption->encrypt($data, $this->password, $this->iv);
+				try{
+					$this->encryption = Encryption::from($method);
+					$ivlen = $this->encryption->iv_len();
+					$this->password = openssl_random_pseudo_bytes($ivlen);
+					$this->iv = openssl_random_pseudo_bytes($ivlen);
+					$this->data = $this->encryption->encrypt($data, $this->password, $this->iv);
+				}catch(Exception $e){}
 				if(++$tries == count($methods)){
 					throw new \Exception("Too many failed attempts to encrypt data");
 				}