/** * Generate a config string from an array. * * @param array $config Array of configuration options. * @return string Configuration string. * @throws InvalidArgumentException Throws an InvalidArgumentException if * any passed-in configuration options are invalid. */ public static function genConfig(array $config = array()) { $defaults = array('rounds' => 5001, 'salt' => Utilities::encode64(Utilities::genRandomBytes(3))); $config = array_merge($defaults, array_change_key_case($config, CASE_LOWER)); $string = '*1'; if (self::validateOptions($config)) { // Rounds needs to be odd in order to avoid exposing weak DES keys if ($config['rounds'] % 2 == 0) { --$config['rounds']; } $string = sprintf('_%s%s', Utilities::encodeInt24($config['rounds']), $config['salt']); } return $string; }