public ISferaService CurrentService() { try { if (_service == null || _service.State == CommunicationState.Faulted) { if (_service != null && _service.State == CommunicationState.Faulted) _service.Abort(); _service = new SferaServiceClient("SferaServiceCompact"); var sc = new SymmetricCryptography<TripleDESCryptoServiceProvider>(Login.Instance.Key, Login.Instance.IV); if (_service.ClientCredentials != null) { _service.ClientCredentials.UserName.UserName = sc.Encrypt(Login.Instance.CurrentLogin().LoginName + "&" + Login.Instance.CurrentLogin().CodiceAzienda); _service.ClientCredentials.UserName.Password = sc.Encrypt(Login.Instance.CurrentLogin().Password); } // Il servizio non deve essere aperto: // http://social.msdn.microsoft.com/Forums/vstudio/en-US/7ac84925-4cef-44fc-87aa-fa6fa366fa19/the-communication-object-channelfactory-cannot-be-modified-while-it-is-in-the-opened-state // _service.Open(); retry: if (_service.State == CommunicationState.Opening) goto retry; } return _service; } catch (Exception ex) { var log = LogManager.GetLogger("Sfera"); log.FatalFormat("Errore nella creazione del servizio - {0} - azienda:{1}", ex, Library.Utility.GetMethodDescription(), Login.Instance.CurrentLogin().Azienda); throw; } }
/// <summary>認証Serviceのテスト(秘密鍵暗号化方式)</summary> private void button1_Click(object sender, EventArgs e) { // SessionステートフルなWebサービス ServiceForAuth sfa = new ServiceForAuth(); sfa.CookieContainer = new CookieContainer(); sfa.Proxy = GlobalProxySelection.GetEmptyWebProxy(); //sfa.Proxy = WebProxy.GetDefaultProxy(); //sfa.Proxy.Credentials = new NetworkCredential("20228749", "*****"); // チャレンジ=秘密鍵 string challenge = sfa.GetChallenge(); // アカウントの暗号化 string encUid = SymmetricCryptography.EncryptString( this.textBox1.Text, challenge, EnumSymmetricAlgorithm.TripleDESCryptoServiceProvider); string encPwd = SymmetricCryptography.EncryptString( this.textBox2.Text, challenge, EnumSymmetricAlgorithm.TripleDESCryptoServiceProvider); // 認証チケットを取得 string authTicketBase64 = sfa.GetAuthTicket(encUid, encPwd); // 認証チケットを検証 string[] authTicket = sfa.ValidateAuthTicket(authTicketBase64); MessageBox.Show( "uid\t: " + authTicket[0] + "\r\n" + "pwd\t: " + authTicket[1] + "\r\n" + "time\t: " + authTicket[2] + "\r\n", "認証チケット", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public string login() { objUserData = new UserData(); CommonAPI.LoginInfo = objUserData; objUserData.uuid = Guid.NewGuid().ToString(); objUserData.WorkStationSerial = Tools.generateWorkStationGUID(); SymmetricCryptography symmetricCryptography_0; //加密器 symmetricCryptography_0 = new SymmetricCryptography(SymmetricProvider.Rijndael); byte[] key = null; byte[] iV = null; //系统默认是根据uuid 生成一个算法key的,或者简单理解为uuid就是加密和解密的密码 CommonAPI.GenerateKey(objUserData.uuid, ref key, ref iV, SymmetricProvider.Rijndael); symmetricCryptography_0.Key = key; symmetricCryptography_0.IV = iV; objUserData.UserId = symmetricCryptography_0.EncryptString(m_strUser); //demo objUserData.Password = symmetricCryptography_0.EncryptString(m_strPassword); //DEMO objUserData.AppServer = m_strServer; objUserData.LanguageID = "zh-CN"; objUserData.cSubID = "DP"; objUserData.operDate = m_strDate; objUserData.DataSource = m_strDataSource; Debugger.Log(0, null, UserDataTools.userData2String(objUserData)); var paras = new CommonParameters(); var loginHeader = new LoginedDataHead(); loginHeader.ChangePwd = false; loginHeader.KickOutWorkStation = false; loginHeader.NewPassword = symmetricCryptography_0.EncryptString(""); //DEMO paras.Para1 = "TARGET\\ENTERPRISEPORTAL.EXE"; paras.Para2 = true; paras.Para3 = loginHeader; try { credit.BFDispatch("Authenticate", objUserData, ref paras); if (!string.IsNullOrEmpty(paras.Para1)) { return(paras.Para1); } } catch (CustomError cEx) { //MessageBox.Show(cEx.Message); throw; } finally { } }
private void OptionEncryptAES_Click(object sender, EventArgs e) { SymmetricCryptography encrypterAES = new SymmetricCryptography(false); string contentToEncrypt = UploadedDocumentClass.GetFileContent(); string encrypted = encrypterAES.EncryptDocumentAES(contentToEncrypt); LoadingScreenForm loadScreen = new LoadingScreenForm(UploadedDocumentClass.GetFileName(), "AES Encryption"); loadScreen.ShowDialog(); SaveToTxt("helpfile_aes_encrypted", encrypted); outputScreen.Text = "Encrypted with AES: \r\n" + encrypted; }
public string[] ValidateAuthTicket(string authTicket) { try { // 認証チケットの復号化 return((string[])BinarySerialize.BytesToObject( CustomEncode.FromBase64String( SymmetricCryptography.DecryptString( authTicket, GetConfigParameter.GetConfigValue("private-key"), EnumSymmetricAlgorithm.TripleDESCryptoServiceProvider)))); } catch { // 認証失敗 return(null); } }
public LoginInfo CurrentLogin() { try { if (System.ServiceModel.OperationContext.Current != null && System.ServiceModel.OperationContext.Current.ServiceSecurityContext != null && System.ServiceModel.OperationContext.Current.ServiceSecurityContext.PrimaryIdentity != null && !string.IsNullOrEmpty(System.ServiceModel.OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name)) { var sc = new SymmetricCryptography<TripleDESCryptoServiceProvider>(Instance.Key, Instance.IV); _currentLogin.LoginName = sc.Decrypt(System.ServiceModel.OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name); } return _currentLogin; } catch { return new LoginInfo(); } //string[] currentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split('\\'); //return new Gipasoft.Security.LoginInfo(currentUser[1], string.Empty, string.Empty, int.MinValue, currentUser[0]); }
private void openService() { try { _service = new SferaServiceClient("SferaServiceCompact"); var sc = new SymmetricCryptography<TripleDESCryptoServiceProvider>(Login.Instance.Key, Login.Instance.IV); if (_service.ClientCredentials != null) { _service.ClientCredentials.UserName.UserName = sc.Encrypt(Login.Instance.CurrentLogin().LoginName + "&" + Login.Instance.CurrentLogin().CodiceAzienda); _service.ClientCredentials.UserName.Password = sc.Encrypt(Login.Instance.CurrentLogin().Password); } _service.Open(); } catch (Exception ex) { _log.FatalFormat("Errore nell'apertura del servizio - {0}", ex, Gipasoft.Library.Utility.GetMethodDescription()); throw; } }
private void OptionDecryptAES_Click(object sender, EventArgs e) { try { SymmetricCryptography decrypterAES = new SymmetricCryptography(true); string contentToDecrypt = UploadedDocumentClass.GetFileContent(); string decrypted = decrypterAES.DecryptDocumentAES(contentToDecrypt); LoadingScreenForm loadScreen = new LoadingScreenForm(UploadedDocumentClass.GetFileName(), "AES Decryption"); loadScreen.ShowDialog(); SaveToTxt("helpfile_aes_decrypted", decrypted); outputScreen.Text = "Decrypted with AES: \r\n" + decrypted; } catch { MessageBox.Show("Document is not valid AES encryption", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void SaveToFile(string s, string fileName, byte[] bytKey, byte[] bytVector) { SymmetricCryptography <TripleDESCryptoServiceProvider> CryptObject = new SymmetricCryptography <TripleDESCryptoServiceProvider>(bytKey, bytVector); FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None); CryptoStream cStream = new CryptoStream(fs, CryptObject._provider.CreateEncryptor(CryptObject.Key, CryptObject.IV), CryptoStreamMode.Write); byte[] bytLicense = ASCIIEncoding.ASCII.GetBytes(s); //Read from the input file, then encrypt and write to the output file. for (int i = 0; i < bytLicense.Length; i++) { cStream.Write(bytLicense, i, 1); } cStream.Close(); cStream.Dispose(); fs.Close(); fs.Dispose(); }
// 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> /// Encrypts the specified input. /// </summary> /// <param name="input">The input.</param> /// <returns></returns> private string Encrypt(string input) { var crypto = new SymmetricCryptography(SymmetricProvider.TripleDES) { Key = _dbLogonInfo.ApplicationId. ToLower() + Definition.CONFIGURATION_KEY, Salt = Definition.CONFIGURATION_SALT }; return crypto.Encrypt(input); }
public UtenteDTO VerifyUser(string codiceAzienda, string username, string password) { try { var sc = new SymmetricCryptography<TripleDESCryptoServiceProvider>(Gipasoft.Security.Login.Instance.Key, Gipasoft.Security.Login.Instance.IV); var frameworkVersion = string.Empty; var frameworkServicePack = string.Empty; try { var fx40ClientInstalled = FrameworkVersionDetection.IsInstalled(FrameworkVersion.Fx40C); var fx40FullInstalled = FrameworkVersionDetection.IsInstalled(FrameworkVersion.Fx40F); if (fx40ClientInstalled) { if (!string.IsNullOrEmpty(frameworkVersion)) frameworkVersion += "; "; if (!string.IsNullOrEmpty(frameworkServicePack)) frameworkServicePack += "; "; frameworkVersion += FrameworkVersionDetection.GetExactVersion(FrameworkVersion.Fx40C) + "C"; var sp = FrameworkVersionDetection.GetServicePackLevel(FrameworkVersion.Fx40C); if (sp > -1) frameworkServicePack += sp + "C"; } if (fx40FullInstalled) { if (!string.IsNullOrEmpty(frameworkVersion)) frameworkVersion += "; "; if (!string.IsNullOrEmpty(frameworkServicePack)) frameworkServicePack += "; "; frameworkVersion += FrameworkVersionDetection.GetExactVersion(FrameworkVersion.Fx40F) + "F"; var sp = FrameworkVersionDetection.GetServicePackLevel(FrameworkVersion.Fx40F); if (sp > -1) frameworkServicePack += sp + "F"; } else if (FrameworkVersionDetection.IsInstalled(FrameworkVersion.Fx35)) { if (!string.IsNullOrEmpty(frameworkVersion)) frameworkVersion += "; "; if (!string.IsNullOrEmpty(frameworkServicePack)) frameworkServicePack += "; "; frameworkVersion += FrameworkVersionDetection.GetExactVersion(FrameworkVersion.Fx35).ToString(); var sp = FrameworkVersionDetection.GetServicePackLevel(FrameworkVersion.Fx35); if (sp > -1) frameworkServicePack += sp.ToString(); } else if (FrameworkVersionDetection.IsInstalled(FrameworkVersion.Fx30)) { if (!string.IsNullOrEmpty(frameworkVersion)) frameworkVersion += "; "; if (!string.IsNullOrEmpty(frameworkServicePack)) frameworkServicePack += "; "; frameworkVersion += FrameworkVersionDetection.GetExactVersion(FrameworkVersion.Fx30).ToString(); var sp = FrameworkVersionDetection.GetServicePackLevel(FrameworkVersion.Fx30); if (sp > -1) frameworkServicePack += sp.ToString(); } else if (FrameworkVersionDetection.IsInstalled(FrameworkVersion.Fx20)) { if (!string.IsNullOrEmpty(frameworkVersion)) frameworkVersion += "; "; if (!string.IsNullOrEmpty(frameworkServicePack)) frameworkServicePack += "; "; frameworkVersion += FrameworkVersionDetection.GetExactVersion(FrameworkVersion.Fx20).ToString(); var sp = FrameworkVersionDetection.GetServicePackLevel(FrameworkVersion.Fx20); if (sp > -1) frameworkServicePack += sp.ToString(); } else if (FrameworkVersionDetection.IsInstalled(FrameworkVersion.Fx11)) { if (!string.IsNullOrEmpty(frameworkVersion)) frameworkVersion += "; "; if (!string.IsNullOrEmpty(frameworkServicePack)) frameworkServicePack += "; "; frameworkVersion += FrameworkVersionDetection.GetExactVersion(FrameworkVersion.Fx11).ToString(); var sp = FrameworkVersionDetection.GetServicePackLevel(FrameworkVersion.Fx11); if (sp > -1) frameworkServicePack += sp.ToString(); } else if (FrameworkVersionDetection.IsInstalled(FrameworkVersion.Fx10)) { if (!string.IsNullOrEmpty(frameworkVersion)) frameworkVersion += "; "; if (!string.IsNullOrEmpty(frameworkServicePack)) frameworkServicePack += "; "; frameworkVersion += FrameworkVersionDetection.GetExactVersion(FrameworkVersion.Fx10).ToString(); var sp = FrameworkVersionDetection.GetServicePackLevel(FrameworkVersion.Fx10); if (sp > -1) frameworkServicePack += sp.ToString(); } } catch (Exception ex) { _log.ErrorFormat("Errore nella lettura del framework corrente - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Gipasoft.Security.Login.Instance.CurrentLogin().Azienda); } var computerName = Environment.MachineName; var computer = new ComputerDTO(); try { computer.ComputerName = computerName; computer.FrameworkVersion = frameworkVersion; computer.FrameworkServicePack = frameworkServicePack; computer.OsBits = OSVersionInfo.OSBits.ToString(); computer.OsEdition = OSVersionInfo.Edition; computer.OsName = OSVersionInfo.Name; computer.OsServicePack = OSVersionInfo.ServicePack; computer.OsVersionString = OSVersionInfo.VersionString; computer.ProcessorBits = OSVersionInfo.ProcessorBits.ToString(); } catch (Exception ex) { _log.ErrorFormat("Errore nella lettura della versione del SO corrente - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Gipasoft.Security.Login.Instance.CurrentLogin().Azienda); } var utente = getServiceClient().VerificaUtente(sc.Encrypt(codiceAzienda), sc.Encrypt(username), sc.Encrypt(password), computer); getServiceClient().Close(); return utente; } catch (EndpointNotFoundException ex) { _log.FatalFormat("Errore nella lettura del framework corrente - ENDPOINNOTFOUND - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Gipasoft.Security.Login.Instance.CurrentLogin().Azienda); throw; } }
public UtenteVerificaDTO VerifyUser(string codiceAzienda, string username, string password, ComputerDTO computerInfo, out IWindsorContainer container) { try { IDaoFactory daoFactory = null; container = null; var sc = new SymmetricCryptography<TripleDESCryptoServiceProvider>(Login.Instance.Key, Login.Instance.IV); username = sc.Decrypt(username); password = sc.Decrypt(password); var windsorConfigRepository = new WindsorConfigRepository(); Azienda azienda = null; if (!string.IsNullOrEmpty(codiceAzienda)) { try { codiceAzienda = sc.Decrypt(codiceAzienda); container = windsorConfigRepository.GetContainer(codiceAzienda); daoFactory = windsorConfigRepository.GetDaoFactory(codiceAzienda); if(daoFactory != null) azienda = daoFactory.GetAziendaDao().GetByCodice(codiceAzienda); else return null; } catch (Exception ex) { _log.ErrorFormat("Errore nel riconoscimento dell'utente - {0} - codiceAzienda:{1} - user:{2} - pwd:{3}", ex, Utility.GetMethodDescription(), codiceAzienda, username, password); throw; } } else { var userAzienda = username.Split('&'); if (userAzienda.Length == 2) { codiceAzienda = userAzienda[1]; container = windsorConfigRepository.GetContainer(codiceAzienda); username = userAzienda[0]; daoFactory = windsorConfigRepository.GetDaoFactory(codiceAzienda); azienda = daoFactory.GetAziendaDao().GetByCodice(codiceAzienda); } } if (azienda != null || string.IsNullOrEmpty(codiceAzienda)) { IList<Utente> users = new List<Utente>(); if (azienda != null) { container = windsorConfigRepository.GetContainer(azienda.ID); users = daoFactory.GetUtenteDao().GetByAzienda(username, password, azienda); } else { // Mi trovo nel caso di validare la password principale, l'utente principale si trova sempre nell'azienda principale "ZETH" try { daoFactory = windsorConfigRepository.GetDaoFactory("ZETH"); container = windsorConfigRepository.GetContainer("ZETH"); var utente = daoFactory.GetUtenteDao().GetByUsername(username, codiceAzienda); if (utente.Password == password) users.Add(utente); } catch (Exception ex) { _log.ErrorFormat("Errore nel riconoscimento dell'utente - ZETH - {0} - user:{1} - pwd:{2} - codiceAzienda:{3}", ex, Utility.GetMethodDescription(), username, password, codiceAzienda); throw; } } if (users.Count > 0) { if (users.Count > 1) _log.ErrorFormat("Trovati più di un utente con stesso username e stessa password - {0} - user:{1} - pwd:{2}", Utility.GetMethodDescription(), username, password); int? idAzienda = null; if (azienda != null) idAzienda = azienda.ID; // Memorizzo log di login if (azienda != null && computerInfo != null) { try { if (container != null) { var context = OperationContext.Current; var messageProperties = context.IncomingMessageProperties; var endpointProperty = messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; IpAddress clientIp = null; if (endpointProperty != null) clientIp = new IpAddress { IpNumber = endpointProperty.Address, IpPort = endpointProperty.Port }; var logService = container.Resolve<ILogTransazioneService>(); logService.AddLog(users[0], computerInfo, clientIp, AzioneUtente.Login); } } catch (Exception ex) { _log.ErrorFormat("Errore nella memorizzazione di informazioni sul computer di collegamento - {0} - user:{1} - password:{2} - nomeComputer:{3} - versioneSO:{4} - versioneFramework:{5}", ex, Utility.GetMethodDescription(), username, password, computerInfo.ComputerName, computerInfo.OsVersionString, computerInfo.FrameworkVersion); } } var utenteVerificaDTO = new UtenteVerificaDTO { Id = users[0].ID, Username = users[0].Username, Password = users[0].Password, IdAzienda = idAzienda }; if (users[0].Referente != null) { utenteVerificaDTO.Cognome = users[0].Referente.PersonaRiferimento.Cognome; utenteVerificaDTO.Nome = users[0].Referente.PersonaRiferimento.Nome; } else { utenteVerificaDTO.Cognome = users[0].Cognome; utenteVerificaDTO.Nome = users[0].Nome; } return utenteVerificaDTO; } return null; } return null; } catch (Exception ex) { _log.ErrorFormat("Errore nel riconoscimento dell'utente - {0} - codiceAzienda:{1} - user:{2} - pwd:{3}", ex, Utility.GetMethodDescription(), codiceAzienda, username, password); throw; } }
public string Decrypt(string testo) { var sc = new SymmetricCryptography<TripleDESCryptoServiceProvider>(Login.Instance.Key, Login.Instance.IV); return sc.Decrypt(testo); }
public CryptoService(byte[] cryptoKey, byte[] cryptoIV) { m_Crypto = new SymmetricCryptography<System.Security.Cryptography.RC2CryptoServiceProvider>(cryptoKey, cryptoIV); }
/// <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); } } } }