public string[] ValidateAuthTicket(string authTicket) { try { // 認証チケットの復号化 return((string[])BinarySerialize.BytesToObject( CustomEncode.FromBase64String( SymmetricCryptography.DecryptString( authTicket, GetConfigParameter.GetConfigValue("private-key"), EnumSymmetricAlgorithm.TripleDESCryptoServiceProvider)))); } catch { // 認証失敗 return(null); } }
// UFSoft.U8.Framework.Login.UI.clsLogin public static UserData DeUserData(string cryptuuid, string s, string string_17) { UserData userData = null; if (s.Length != 0) { byte[] iV = null; byte[] key = null; SymmetricCryptography symm = new SymmetricCryptography(SymmetricProvider.Rijndael); CommonAPI.GenerateKey(cryptuuid, ref key, ref iV, SymmetricProvider.Rijndael); symm.Key = key; symm.IV = iV; StringReader stringReader = new StringReader(s); XmlTextReader xmlTextReader = CustomTypeAlias.CreateXmlReader(stringReader); userData = new UserData(); while (xmlTextReader.Read()) { if (xmlTextReader.NodeType == XmlNodeType.Element && xmlTextReader.LocalName == "Entry") { userData.UserId = symm.DecryptString(xmlTextReader.GetAttribute("user")); userData.Password = symm.DecryptString(xmlTextReader.GetAttribute("data")); userData.AccID = symm.DecryptString(xmlTextReader.GetAttribute("accid")); userData.AppServer = symm.DecryptString(xmlTextReader.GetAttribute("appserver")); userData.cSubID = symm.DecryptString(xmlTextReader.GetAttribute("subid")); userData.iYear = symm.DecryptString(xmlTextReader.GetAttribute("iyear")); userData.ConnString = symm.DecryptString(xmlTextReader.GetAttribute("connstring")); userData.operDate = symm.DecryptString(xmlTextReader.GetAttribute("operdate")); userData.DataSource = symm.DecryptString(xmlTextReader.GetAttribute("datasource")); userData.LanguageID = symm.DecryptString(xmlTextReader.GetAttribute("languageid")); userData.WorkStationSerial = symm.DecryptString(xmlTextReader.GetAttribute("workstationserial")); userData.RightServer = symm.DecryptString(xmlTextReader.GetAttribute("rightserver")); userData.IsCompanyVer = bool.Parse(symm.DecryptString(xmlTextReader.GetAttribute("iscompanyver"))); userData.SecondConnString = (Hashtable)CustomXmlSerializer.Deserialize(symm.DecryptString(xmlTextReader.GetAttribute("secondconnstring")), "Hashtable"); userData.EmployeeId = symm.DecryptString(xmlTextReader.GetAttribute("employeeid")); userData.IsAdmin = bool.Parse(symm.DecryptString(xmlTextReader.GetAttribute("isadmin"))); userData.UserName = symm.DecryptString(xmlTextReader.GetAttribute("username")); userData.AccName = symm.DecryptString(xmlTextReader.GetAttribute("accname")); userData.EntTypeID = symm.DecryptString(xmlTextReader.GetAttribute("enttypeid")); userData.iMonth = int.Parse(symm.DecryptString(xmlTextReader.GetAttribute("imonth"))); userData.AppServerSerial = symm.DecryptString(xmlTextReader.GetAttribute("appServerserial")); userData.Roles = symm.DecryptString(xmlTextReader.GetAttribute("roles")); userData.ProtocolPort = (Hashtable)CustomXmlSerializer.Deserialize(symm.DecryptString(xmlTextReader.GetAttribute("protocolport")), "protocolport"); userData.BarCode = symm.DecryptString(xmlTextReader.GetAttribute("barcode")); userData.Customer = symm.DecryptString(xmlTextReader.GetAttribute("customer")); userData.AuthenMode = int.Parse(symm.DecryptString(xmlTextReader.GetAttribute("authenmode"))); userData.AuthenExtraInfo = symm.DecryptString(xmlTextReader.GetAttribute("authenextrainfo")); userData.IndustryType = symm.DecryptString(xmlTextReader.GetAttribute("industrytype")); userData.iBeginYear = symm.DecryptString(xmlTextReader.GetAttribute("ibeginyear")); userData.AIOServer = symm.DecryptString(xmlTextReader.GetAttribute("aiosrv")); if (xmlTextReader.GetAttribute("crmsrv") != null && FIELDMAP.ContainsKey("CrmServer")) { //userData.CrmServer = symm.DecryptString(xmlTextReader.GetAttribute("crmsrv")); FIELDMAP["CrmServer"].SetValue(userData, symm.DecryptString(xmlTextReader.GetAttribute("crmsrv"))); } if (xmlTextReader.GetAttribute("utusrv") != null && FIELDMAP.ContainsKey("UTUServer")) { //userData.UTUServer = symm.DecryptString(xmlTextReader.GetAttribute("utusrv")); FIELDMAP["UTUServer"].SetValue(userData, symm.DecryptString(xmlTextReader.GetAttribute("utusrv"))); } if (xmlTextReader.GetAttribute("remind") != null && FIELDMAP.ContainsKey("isRemind")) { FIELDMAP["isRemind"].SetValue(userData, bool.Parse(symm.DecryptString(xmlTextReader.GetAttribute("remind")))); } if (xmlTextReader.GetAttribute("usermode") != null && FIELDMAP.ContainsKey("UserMode")) { FIELDMAP["UserMode"].SetValue(userData, int.Parse(symm.DecryptString(xmlTextReader.GetAttribute("usermode")))); } if (xmlTextReader.GetAttribute("sps") != null && FIELDMAP.ContainsKey("ValidateSPS")) { FIELDMAP["ValidateSPS"].SetValue(userData, bool.Parse(symm.DecryptString(xmlTextReader.GetAttribute("sps")))); } if (xmlTextReader.GetAttribute("sysdate") != null && FIELDMAP.ContainsKey("sysdate")) { FIELDMAP["sysdate"].SetValue(userData, symm.DecryptString(xmlTextReader.GetAttribute("sysdate"))); } if (string.IsNullOrEmpty(string_17)) { userData.Auditor = new AuditorContext { AuditorId = userData.UserId, AuditorName = userData.UserName }; } else { userData.Auditor = (AuditorContext)CustomXmlSerializer.Deserialize(symm.DecryptString(string_17), "AuditorContext"); } xmlTextReader.Close(); stringReader.Close(); } } } userData.uuid = cryptuuid; return(userData); }
public string GetAuthTicket(string encUid, string encPwd) { try { // ユーザIDの復号化 string uid = SymmetricCryptography.DecryptString( encUid, (string)Session["challenge"], EnumSymmetricAlgorithm.TripleDESCryptoServiceProvider); // パスワードの復号化 string pwd = SymmetricCryptography.DecryptString( encPwd, (string)Session["challenge"], EnumSymmetricAlgorithm.TripleDESCryptoServiceProvider); // 認証する。 bool isAuthenticated = false; #region 認証処理のUOC // ★★ コンテキストの情報を使用するなどして // 認証処理をUOCする(必要に応じて)。 //// B層・D層呼出し //// 認証チェックとタイムスタンプの更新 //MyUserInfo userInfo =new MyUserInfo( // "未認証:" + uid, HttpContext.Current.Request.UserHostAddress); //BaseReturnValue returnValue = (BaseReturnValue)Latebind.InvokeMethod( // "xxxx", "yyyy", // FxLiteral.TRANSMISSION_INPROCESS_METHOD_NAME, // new object[] { // new AuthParameterValue("-", "-", "zzzz", "",userInfo, pwd), // DbEnum.IsolationLevelEnum.User }); //// 認証されたか・されなかったか //isAuthenticated = !returnValue.ErrorFlag; isAuthenticated = true; #endregion if (isAuthenticated) { // 認証チケットを作成して暗号化する(DateTime.Nowにより可変に)。 string[] authTicket = { uid, pwd, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") }; return(SymmetricCryptography.EncryptString( CustomEncode.ToBase64String( BinarySerialize.ObjectToBytes(authTicket)), GetConfigParameter.GetConfigValue("private-key"), EnumSymmetricAlgorithm.TripleDESCryptoServiceProvider)); } else { // 認証失敗 return(string.Empty); } } catch { // 認証失敗 return(string.Empty); } finally { // セッションの解放 Session.Abandon(); } }
/// <summary>秘密鍵・復号化</summary> private void button2_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtSCSalt.Text)) { // ソルト無し if (this.rbnSCString.Checked) { // String this.txtSCString.Text = SymmetricCryptography.DecryptString( this.txtSCCode.Text, this.txtSCPassword.Text, (EnumSymmetricAlgorithm)cbxSCPV.SelectedValue); } else { // Bytes this.txtSCString.Text = CustomEncode.ByteToString( SymmetricCryptography.DecryptBytes( CustomEncode.FormHexString(this.txtSCCode.Text), this.txtSCPassword.Text, (EnumSymmetricAlgorithm)cbxSCPV.SelectedValue), CustomEncode.UTF_8); } } else { // ソルト有り if (this.nudSCStretching.Value == 0) { // ストレッチング無し if (this.rbnSCString.Checked) { // String this.txtSCString.Text = SymmetricCryptography.DecryptString( this.txtSCCode.Text, this.txtSCPassword.Text, (EnumSymmetricAlgorithm)cbxSCPV.SelectedValue, CustomEncode.StringToByte(txtSCSalt.Text, CustomEncode.UTF_8)); } else { // Bytes this.txtSCString.Text = CustomEncode.ByteToString( SymmetricCryptography.DecryptBytes( CustomEncode.FormHexString(this.txtSCCode.Text), this.txtSCPassword.Text, (EnumSymmetricAlgorithm)cbxSCPV.SelectedValue, CustomEncode.StringToByte(txtSCSalt.Text, CustomEncode.UTF_8)), CustomEncode.UTF_8); } } else { // ストレッチング有り if (this.rbnSCString.Checked) { // String this.txtSCString.Text = SymmetricCryptography.DecryptString( this.txtSCCode.Text, this.txtSCPassword.Text, (EnumSymmetricAlgorithm)cbxSCPV.SelectedValue, CustomEncode.StringToByte(txtSCSalt.Text, CustomEncode.UTF_8), (int)this.nudSCStretching.Value); } else { // Bytes this.txtSCString.Text = CustomEncode.ByteToString( SymmetricCryptography.DecryptBytes( CustomEncode.FormHexString(this.txtSCCode.Text), this.txtSCPassword.Text, (EnumSymmetricAlgorithm)cbxSCPV.SelectedValue, CustomEncode.StringToByte(txtSCSalt.Text, CustomEncode.UTF_8), (int)this.nudSCStretching.Value), CustomEncode.UTF_8); } } } }