/// <summary> /// 将加密之后的ticket对应字符转换回来 /// </summary> /// <param name="strTicketEncoded">待解密的字符串原始数据</param> /// <returns>解密之后的ticket对象</returns> /// <remarks> /// 解密的源数据要求采用相同加密格式要求,配置于PassportEncryptionSettings中 /// </remarks> public static ITicket DecryptTicket(string strTicketEncoded) { ITicketEncryption et = PassportEncryptionSettings.GetConfig().TicketEncryption; byte[] data = Convert.FromBase64String(strTicketEncoded); return(et.DecryptTicket(data, PassportClientSettings.GetConfig().RsaKeyValue)); }
/// <summary> /// 加密Ticket /// </summary> /// <param name="ticket">ticket</param> /// <returns>加密后的Ticket并且使用Base64编码</returns> public static string EncryptTicket(ITicket ticket) { ITicketEncryption et = PassportEncryptionSettings.GetConfig().TicketEncryption; //byte[] data = et.EncryptTicket(ticket, PassportClientSettings.GetConfig().RsaKeyValue); /del by yuanyong 20090416 //原来是PassportClientSettings,不正确的。加密ticket是PassportService的事情。虽然Client和Service都配置了密钥,但是应该使用Service方的 byte[] data = et.EncryptTicket(ticket, PassportSignInSettings.GetConfig().RsaKeyValue); return(Convert.ToBase64String(data)); }
/// <summary> /// 单点登录加密配置信息 /// </summary> /// <returns></returns> /// <remarks> /// <code source="..\Framework\TestProjects\DeluxeWorks.Library.Passport.Test\ConfigurationTest.cs" region="PassportEncryptionSettingsTest" lang="cs" title="获取加解密Ticket的配置信息" /> /// </remarks> public static PassportEncryptionSettings GetConfig() { PassportEncryptionSettings result = (PassportEncryptionSettings)ConfigurationBroker.GetSection("passportEncryptionSettings"); if (result == null) { result = new PassportEncryptionSettings(); } return(result); }
/// <summary> /// 解密票据形成ITicket对象 /// </summary> /// <param name="strTicketEncoded"></param> /// <returns></returns> public static ITicket DecryptTicket(string strTicketEncoded) { ITicket ticket = null; ITicketEncryption et = PassportEncryptionSettings.GetConfig().TicketEncryption; try { byte[] data = Convert.FromBase64String(strTicketEncoded); ticket = et.DecryptTicket(data, PassportClientSettings.GetConfig().RsaKeyValue); } catch (System.Exception ex) { if (ex is CryptographicException || ex is System.IO.EndOfStreamException || ex is SystemSupportException || ex is FormatException) { throw; } } return(ticket); }
/// <summary> /// 解密字符串,将加密后的Base64的字符串解密为原始字符串 /// </summary> /// <param name="strEncText">加密后的Base64</param> /// <returns>解密后的原始字符串</returns> public static string DecryptString(string strEncText) { byte[] data = Convert.FromBase64String(strEncText); return(PassportEncryptionSettings.GetConfig().StringEncryption.DecryptString(data)); }
/// <summary> /// 加密字符串,返回加密后的Base64的字符串 /// </summary> /// <param name="strData">原始字符串</param> /// <returns>加密后的Base64的字符串</returns> public static string EncryptString(string strData) { return(Convert.ToBase64String(PassportEncryptionSettings.GetConfig().StringEncryption.EncryptString(strData))); }