2011-03-28 91 views
2

有這樣的桌面應用程序 似乎工作,但最終作爲令牌返回加密SAML 你能提示我如何解密它如何解密SAML令牌

class Program 
    { 
    static void Main(string[] args) 
    { 
     ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationCallback; 

     var samlToken = GetSamlToken("@domain", "@login", "@password"); 

     Console.WriteLine(Uri.UnescapeDataString(samlToken)); 
     Console.ReadLine(); 
    } 
    private static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
    { 
     return sslPolicyErrors == SslPolicyErrors.None 
      || string.Equals(certificate.Issuer, "CN=Name", StringComparison.InvariantCultureIgnoreCase); 
    } 
    private static string GetSamlToken(string domain, string userName, string password) 
    { 

     var acsUrl = "@RPURL"; 

     var stsUrl = "@stsurl"; 

     WSTrustChannelFactory trustChannelFactory = 
      new WSTrustChannelFactory(new WindowsWSTrustBinding(SecurityMode.TransportWithMessageCredential), 
       new EndpointAddress(new Uri(stsUrl))); 

     trustChannelFactory.TrustVersion = TrustVersion.WSTrust13; 
     trustChannelFactory.Credentials.Windows.ClientCredential.Domain = domain; 
     trustChannelFactory.Credentials.Windows.ClientCredential.UserName = userName; 
     trustChannelFactory.Credentials.Windows.ClientCredential.Password = password; 

     try 
     { 
      RequestSecurityToken rst = 
       new RequestSecurityToken(WSTrust13Constants.RequestTypes.Issue, WSTrust13Constants.KeyTypes.Bearer); 
      rst.AppliesTo = new EndpointAddress(acsUrl); 
      rst.TokenType = Microsoft.IdentityModel.Tokens.SecurityTokenTypes.Saml2TokenProfile11; 

      WSTrustChannel channel = (WSTrustChannel)trustChannelFactory.CreateChannel(); 
      GenericXmlSecurityToken token = channel.Issue(rst) as GenericXmlSecurityToken; 
      string tokenString = token.TokenXml.OuterXml; 

      return tokenString; 
     } 
     finally 
     { 
      trustChannelFactory.Close(); 
     } 
    } 
} 

感謝

回答