encrypt() public static method

Encrypt plaintext
public static encrypt ( string $plaintext, string $password, integer $cost ) : string
$plaintext string Plaintext string to encrypt.
$password string Password used to encrypt data.
$cost integer Number of HMAC iterations to perform on key
return string
Beispiel #1
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testEngine()
 {
     $input = 'AAAAAAAA';
     $key = 'AAAAAAAA';
     $encrypted = Aes::encrypt($input, $key);
     $this->assertEquals($input, Aes::decrypt($encrypted, $key));
     // Perform a validation by replacing a random byte to make sure
     // the decryption fails. After enough successful runs,
     // all areas of the cypher text will have been tested
     // for integrity
     $corrupt = self::swaprandbyte($encrypted);
     Aes::decrypt($corrupt, $key);
 }
 public function testCrossDecryptFailure()
 {
     $pw = 'password';
     $encrypted = \Dcrypt\Aes::encrypt('hello world', $pw);
     try {
         \Dcrypt\AesCtr::decrypt($encrypted, $pw);
         $this->assertTrue(false);
     } catch (\Exception $ex) {
         $this->assertTrue(true);
     }
     try {
         \Dcrypt\Mcrypt::decrypt($encrypted, $pw);
         $this->assertTrue(false);
     } catch (\Exception $ex) {
         $this->assertTrue(true);
     }
     $encrypted = \Dcrypt\AesCtr::encrypt('hello world', $pw);
     try {
         \Dcrypt\Aes::decrypt($encrypted, $pw);
         $this->assertTrue(false);
     } catch (\Exception $ex) {
         $this->assertTrue(true);
     }
 }
Beispiel #3
0
 public static function repoEncodeWeb($repo)
 {
     return base32_encode(\Dcrypt\Aes::encrypt($repo, self::key . \Session::getId() . self::githubId()));
 }