Esempio n. 1
0
 /**
  * Hash then encrypt a password
  * 
  * @param string $password   - The user's password
  * @param Key $secret_key - The master key for all passwords
  * @return string
  */
 public static function hash($password, \ParagonIE\Halite\Contract\CryptoKeyInterface $secret_key)
 {
     // First, let's calculate the hash
     $hashed = \Sodium\crypto_pwhash_scryptsalsa208sha256_str($password, \Sodium\CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_INTERACTIVE, \Sodium\CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_INTERACTIVE);
     // Now let's encrypt the result
     return Symmetric::encrypt($hashed, $secret_key);
 }
Esempio n. 2
0
 /**
  * Encrypt a string using asymmetric cryptography
  * Wraps Symmetric::encrypt()
  * 
  * @param string $source Plaintext
  * @param string $ourPrivateKey Our private key
  * @param string $theirPublicKey Their public key
  * @param boolean $raw Don't hex encode the output?
  * 
  * @return string
  */
 public static function encrypt($source, Contract\CryptoKeyInterface $ourPrivateKey, Contract\CryptoKeyInterface $theirPublicKey, $raw = false)
 {
     list($secret, $public) = self::judgeKeys($ourPrivateKey, $theirPublicKey);
     $ecdh = new Key(self::getSharedSecret($secret, $public), false, false);
     $ciphertext = Symmetric::encrypt($source, $ecdh, $raw);
     unset($ecdh);
     return $ciphertext;
 }
Esempio n. 3
0
 public function testRawEncrypt()
 {
     $key = new \ParagonIE\Halite\Key(\str_repeat('A', 32));
     $message = Symmetric::encrypt('test message', $key, true);
     $this->assertTrue(strpos($message, \ParagonIE\Halite\Halite::HALITE_VERSION) === 0);
     $plain = Symmetric::decrypt($message, $key, true);
     $this->assertEquals($plain, 'test message');
 }