protected static function mcryptKey($key, $options)
	{
		$debug = \bdk\Debug::getInstance();
		if (Str::isBase64Encoded($key) && ( strlen($key) >= $options['key_size'] * 1.333 && strlen($key) <= $options['key_size'] * 1.5)) {
			$debug->log('base64 decoding key');
			$key = base64_decode($key);
		}
		$ascii = true;
		for ($i=0; $i<strlen($key); $i++) {
			if (0x80 & ord($key{$i})) {
				$ascii = false;
				break;
			}
		}
		if ($ascii) {
			$debug->log('hashing ascii key');
			$new_key	= '';
			$num_segs	= ceil($options['key_size']/20);		// 20 is length of raw sha1 output
			$seg_length	= ceil(strlen($key)/$num_segs);
			for ($i=0; $i<$num_segs; $i++) {
				$substr = substr($key, $i*$seg_length, $seg_length);
				$new_key .= sha1($substr, true);
			}
			$key = $new_key;
		}
		if (strlen($key) > $options['key_size']) {
			$debug->log('sizing key');
			$key = substr($key, 0, $options['key_size']);
		}
		return $key;
	}