public static function SetCookie($CookieName, $KeyData, $CookieContents, $CookieExpires, $Path = NULL, $Domain = NULL, $CookieHashMethod = NULL, $CookieSalt = NULL) {
      
      if (is_null($Path))
         $Path = Gdn::Config('Garden.Cookie.Path', '/');

      if (is_null($Domain))
         $Domain = Gdn::Config('Garden.Cookie.Domain', '');

      // If the domain being set is completely incompatible with the current domain then make the domain work.
      $CurrentHost = Gdn::Request()->Host();
      if (!StringEndsWith($CurrentHost, trim($Domain, '.')))
         $Domain = '';
   
      if (!$CookieHashMethod)
         $CookieHashMethod = Gdn::Config('Garden.Cookie.HashMethod');
      
      if (!$CookieSalt)
         $CookieSalt = Gdn::Config('Garden.Cookie.Salt');
      
      // Create the cookie signature
      $KeyHash = self::_Hash($KeyData, $CookieHashMethod, $CookieSalt);
      $KeyHashHash = self::_HashHMAC($CookieHashMethod, $KeyData, $KeyHash);
      $Cookie = array($KeyData, $KeyHashHash, time());
      
      // Attach cookie payload
      if (!is_null($CookieContents)) {
         $CookieContents = (array)$CookieContents;
         $Cookie = array_merge($Cookie, $CookieContents);
      }
      
      $CookieContents = implode('|',$Cookie);

      // Create the cookie.
      setcookie($CookieName, $CookieContents, $CookieExpires, $Path, $Domain, NULL, TRUE);
      $_COOKIE[$CookieName] = $CookieContents;
   }