private static string GenerateKerberosAuthHeader(string host) { AuthenticationContext authenticationContext = null; string result; try { authenticationContext = new AuthenticationContext(); byte[] inputBuffer = null; byte[] bytes = null; string spn = CommandInvocation.spnPrefixForHttp + host; authenticationContext.InitializeForOutboundNegotiate(AuthenticationMechanism.Kerberos, spn, null, null); SecurityStatus securityStatus = authenticationContext.NegotiateSecurityContext(inputBuffer, out bytes); if (securityStatus != SecurityStatus.OK && securityStatus != SecurityStatus.ContinueNeeded) { result = null; } else { string @string = Encoding.ASCII.GetString(bytes); result = CommandInvocation.prefixForKerbAuthBlob + @string; } } finally { if (authenticationContext != null) { authenticationContext.Dispose(); authenticationContext = null; } } return(result); }