Encrypt string using openSSL module
@param string $textToEncrypt
@param string $secretHash Any random secure SALT string for your website
@param string $password User's optional password
@return null|string
777230
public static function encryptOpenssl($textToEncrypt, string $secretHash = null, string $password = ''): ? string
  {
    if ( !$secretHash ){
      $secretHash = self::$salt;
    }
    if ( $length = openssl_cipher_iv_length(self::$method) ){
      $iv = substr(md5(self::$prefix.$password), 0, $length);
      return openssl_encrypt($textToEncrypt, self::$method, $secretHash, true, $iv);
    }
    return null;
  }
161110
public static function cryptHash($password)
    {
        $salt = substr(base64_encode(chr(mt_rand(0, 255))), 0, 2);
        $salt = str_replace('+', '.', $salt);
        return crypt($password, $salt);
    }
388712
public static function decryptString( $text, $salt, $urlDecode = false )
    {
        $_key = sha1( $salt, true );

        // PHP v5.6+ no longer pads strings with nulls for optimal length.
        // This replicates the missing feature.
        if ( version_compare( PHP_VERSION, '5.6.0', '>=' ) )
        {
            // sha1 hashes are always 20 characters. 24 is required.
            $_key .= "\0\0\0\0";
        }

        return trim(
            \mcrypt_decrypt(
                MCRYPT_RIJNDAEL_256,
                $_key,
                \base64_decode( $urlDecode ? urldecode( $text ) : $text ),
                MCRYPT_MODE_ECB,
                \mcrypt_create_iv( \mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ), MCRYPT_RAND )
            )
        );
    }
456091
public function hashPassword($plaintext, array $options = array())
	{
		// Use the password extension if able
		if (version_compare(PHP_VERSION, '7.2', '>=') && \defined('PASSWORD_ARGON2I'))
		{
			return password_hash($plaintext, PASSWORD_ARGON2I, $options);
		}

		// Use the sodium extension (PHP 7.2 native or PECL 2.x) if able
		if (\function_exists('sodium_crypto_pwhash_str_verify'))
		{
			$hash = sodium_crypto_pwhash_str(
				$plaintext,
				SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
				SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
			);
			sodium_memzero($plaintext);

			return $hash;
		}

		// Use the libsodium extension (PECL 1.x) if able
		if (\extension_loaded('libsodium'))
		{
			$hash = \Sodium\crypto_pwhash_str(
				$plaintext,
				\Sodium\CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
				\Sodium\CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
			);
			\Sodium\memzero($plaintext);

			return $hash;
		}

		throw new \LogicException('Argon2i algorithm is not supported.');
	}
276405
public static function generateTokenHash($host, $uri, $token, $secret)
    {
        $m0 = static::$tokenHashMagics[ord(substr($secret, -1, 1)) % 4];
        $m1 = static::$tokenHashMagics[ord(substr($secret, -2, 1)) % 4];
        $m2 = static::$tokenHashMagics[ord(substr($secret, -3, 1)) % 4];
        $m3 = static::$tokenHashMagics[ord(substr($secret, -4, 1)) % 4];

        $sha1 = sha1(
                $m0
                . $host
                . $m1
                . $uri
                . $m2
                . $token
                . $m3
                . $secret
        );

        return substr($sha1, 3, 4)
                . substr($sha1, 33, 4)
                . substr($sha1, 17, 4)
                . substr($sha1, 25, 4);
    }
171129
public static char[] encrypt(char[] password)
	{
		if (password == null || password.length == 0)
		{
			return null;
		}

		try
		{
			String encryptedString = null;

			SecretKeySpec key = new SecretKeySpec(init, "Blowfish");
			Cipher cipher = Cipher.getInstance(CIPHER_INSTANCE);
			cipher.init(Cipher.ENCRYPT_MODE, key);
			byte[] encrypted = cipher.doFinal(String.valueOf(password).getBytes(Charset.forName("UTF8")));
			encryptedString = byteArrayToHexString(encrypted);

			return encryptedString.toCharArray();
		}
		catch (Exception e)
		{
			throw new SecurityException("Unable to encrypt password", e);
		}
	}
587247
def hash_password(plaintextpw: str,
                  log_rounds: int = BCRYPT_DEFAULT_LOG_ROUNDS) -> str:
    
    salt = bcrypt.gensalt(log_rounds)  # optional parameter governs complexity
    hashedpw = bcrypt.hashpw(plaintextpw, salt)
    return hashedpw
989179
public static String encrypt(String salt, String password, String plainText) {
        SecretKey secret = getKey(salt, password);
        return encryptBouncyCastle(secret, plainText);
    }
1262235
public function ntPasswordHash($password = null)
    {
        //if (isset($password)) {
        if (!is_null($password)) {
            return pack('H*',hash('md4', $this->str2unicode($password)));
        } else {
            return pack('H*',hash('md4', $this->str2unicode($this->password)));
        }
    }
709030
public function hashPassword($plainTextPassword) {

		if(strlen($plainTextPassword) < self::MIN_LENGTH) {
			throw new \InvalidArgumentException(sprintf("Password too short. Minimum length is %d.", self::MIN_LENGTH));
		}
		
		if(strlen($plainTextPassword) > self::MAX_LENGTH) {
			throw new \InvalidArgumentException(sprintf("Password too long. Maximum length is %d.", self::MAX_LENGTH));
		}
		
		return password_hash($plainTextPassword, PASSWORD_DEFAULT, ['cost' => $this->cost]);
		
	}
911237
static public function isSameHashAlgorithm($secretPassphrase, $hashAlgorithm)
    {
        if (strlen(static::getComputedSignature($secretPassphrase, $hashAlgorithm)) == strlen(static::getSignature())) {
            return true;
        }

        return false;
    }
871360
public static String computePasswordHash(final String password, final String salt) {
    return computePasswordHash(password, stringToSalt(salt));
  }
1191821
public static String createHash(char[] password) throws NoSuchAlgorithmException, InvalidKeySpecException {

    final SecureRandom random = new SecureRandom();
    final byte[] salt = new byte[SALT_BYTES];
    random.nextBytes(salt);

    final byte[] hash = pbkdf2(password, salt, PBKDF2_ITERATIONS, HASH_BYTES);
    // format iterations:salt:hash
    return PBKDF2_ITERATIONS + ":" + toHex(salt) + ":" + toHex(hash);
  }
1269909
function encrypt(input, secret) {
  if (!secret) {
    return new Error('A \'secret\' is required to encrypt');
  }


  var salt = cryptoLib.randomBytes(KEY_LENGTH / 8),
    iv = cryptoLib.randomBytes(16);

  try {

    var key = cryptoLib.pbkdf2Sync(secret, salt, ITERATIONS, KEY_LENGTH / 8, 'sha1'),
      cipher = cryptoLib.createCipheriv(CIPHER, key, iv);

    var encryptedValue = cipher.update(input, 'utf8', 'base64');
    encryptedValue += cipher.final('base64');

    var result = {
      cipher: CIPHER,
      keyDerivation: KEY_DERIVATION,
      keyLength: KEY_LENGTH,
      iterations: ITERATIONS,
      iv: iv.toString('base64'),
      salt: salt.toString('base64'),
      value: encryptedValue
    };
    return result;

  } catch (err) {
    return new Error('Unable to encrypt value due to: ' + err);
  }
}
477190
public static function fromSealed(
        PasswordInterface $password,
        string $sealed,
        bool $validate = true,
        callable $keyProvider = null,
        callable $saltGenerator = null
    ): Token {
        $parts = explode('*', $sealed);
        if (count($parts) !== 8) {
            throw new InvalidTokenException('Invalid token structure.');
        }

        list($version, $pwId, $salt, $iv, $cipherText, $ttd, $macSalt, $mac)
            = $parts;

        if ($version !== Token::MAC_PREFIX . Token::MAC_FORMAT_VERSION) {
            throw new InvalidTokenException('Invalid token version.');
        }

        if ($pwId !== $password->getId()) {
            throw new PasswordMismatchException(
                $password->getId(), 
                $pwId, 
                "Token encrypted with password $pwId; password"
                    . " {$password->getId()} provided for validation."
            );
        }

        $token = new self(
            $password,
            $salt,
            base64_decode($iv),
            base64_decode($cipherText),
            $ttd,
            $keyProvider,
            $saltGenerator
        );

        if ($validate) {
            if ($token->isExpired()) {
                throw new ExpiredTokenException('Token expired on '
                    . DateTime::createFromFormat('U', $ttd)->format('c'));
            }

            $token->validateChecksum($macSalt, $mac);
        }

        return $token;
    }
1190293
public String encryptPassword(String userPassword) throws NoSuchAlgorithmException, InvalidKeySpecException {
        char[] chars = userPassword.toCharArray();
        byte[] salt = getSalt();

        PBEKeySpec spec = new PBEKeySpec(chars, salt, iterations, keyLength);
        SecretKeyFactory skf = SecretKeyFactory.getInstance(keyAlgorythm);
        byte[] hash = skf.generateSecret(spec).getEncoded();
        return toHex((iterations + ":" + toHex(salt) + ":" + toHex(hash)).getBytes());
    }
1275908
public static function cryptVerify($password, $hash)
    {
        $salt = substr($hash, 0, 2);
        try {
            // PHP 7 throws exception for invalid salt
            $actual = crypt($password, $salt);
        } catch (\Exception $e) {
            return false;
        }
        return ($actual === $hash);
    }