如何使用System.Cryptography解密EncryptedAssertion

编程入门 行业动态 更新时间:2024-10-25 10:27:38
本文介绍了如何使用System.Cryptography解密EncryptedAssertion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

身份提供者正在使用组件pro的功能对Saml断言进行加密

The Identity provider is encrypting the Saml Assertion using the functions of component pro

Dim encryptedSamlAssertion As New EncryptedAssertion(samlAssertion, encryptingCert, New System.Security.Cryptography.Xml.EncryptionMethod(SamlKeyAlgorithm.Aes256Cbc))

在服务提供商处,我试图解密断言.但是我不能使用component pro.我必须使用System.Security.Cryptography

At the Service Provider I am trying to Decrypt the assertion. But I cannot use component pro. I have to use System.Security.Cryptography

  • X509证书用于加密和解密
  • Aes256Cbc是加密算法

请帮助我提供更多有关如何使用X509Certificate和Aes256Cbc算法解密SamlAssertions的信息

Please help in providing me some more information on how can I achieve Decryption of SamlAssertions using X509Certificate and Aes256Cbc Algorithm

推荐答案

private class Saml2SSOSecurityTokenResolver : SecurityTokenResolver { List<SecurityToken> _tokens; public Saml2SSOSecurityTokenResolver(List<SecurityToken> tokens) { _tokens = tokens; } protected override bool TryResolveSecurityKeyCore(System.IdentityModel.Tokens.SecurityKeyIdentifierClause keyIdentifierClause, out System.IdentityModel.Tokens.SecurityKey key) { var token = _tokens[0] as X509SecurityToken; var myCert = token.Certificate; key = null; var ekec = keyIdentifierClause as EncryptedKeyIdentifierClause; if (ekec != null) { if (ekec.EncryptionMethod == "www.w3/2001/04/xmlenc#rsa-1_5") { var encKey = ekec.GetEncryptedKey(); var rsa = myCert.PrivateKey as RSACryptoServiceProvider; var decKey = rsa.Decrypt(encKey, false); key = new InMemorySymmetricSecurityKey(decKey); return true; } var data = ekec.GetEncryptedKey(); var id = ekec.EncryptingKeyIdentifier; } return true; } protected override bool TryResolveTokenCore(System.IdentityModel.Tokens.SecurityKeyIdentifierClause keyIdentifierClause, out System.IdentityModel.Tokens.SecurityToken token) { throw new NotImplementedException(); } protected override bool TryResolveTokenCore(System.IdentityModel.Tokens.SecurityKeyIdentifier keyIdentifier, out System.IdentityModel.Tokens.SecurityToken token) { throw new NotImplementedException(); } }

更多推荐

如何使用System.Cryptography解密EncryptedAssertion

本文发布于:2023-11-16 19:44:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607202.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   System   EncryptedAssertion   Cryptography

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!