public MMConMgr() { typeof(ConfigurationElementCollection).GetField("bReadOnly", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(ConfigurationManager.ConnectionStrings, false); ConfigurationManager.ConnectionStrings.Clear(); kpBaseKey = new KeyPair(KeyType.AES, sDefaultPass); FileName = MMExt.MMConLocation() + "\\" + sDefaultName + ".cons"; if (!Directory.Exists(MMExt.MMConLocation() + "\\")) { Directory.CreateDirectory(MMExt.MMConLocation() + "\\"); } ivFile = new FileVar(FileName); Load(); }
public MMCredentialStore(string aMasterPwd, string aFileName) { string sFileName = (aFileName == ""? "\\MachineCredentialStoreRoot.Cert" : aFileName); if (aMasterPwd == "") { PasswordDialog pd = new PasswordDialog(); if (pd.ShowDialog() != DialogResult.OK) { throw new Exception("Password not present. Aborting start."); } else { sMasterPwd = pd.sPassword; if (sMasterPwd == "") { throw new Exception("Password not present. Aborting start."); } } } else { sMasterPwd = aMasterPwd; } //sFileName = MMExt.MMConLocation() + sFileName; string sPriCert = ""; string sPubCert = ""; Boolean bRootCertFound = true; if (File.Exists(sFileName)) { fvMain = new FileVar(sFileName); if (sMasterPwd != "") { try { kpMain = new KeyPair(KeyType.AES, sMasterPwd); } catch { bRootCertFound = false; } } if (bRootCertFound) { string sUVPriCert = fvMain["RootPrivateCert"]; if (sUVPriCert != "") { try { sPriCert = kpMain.toDecryptAES(sUVPriCert); } catch { bRootCertFound = false; } } else { bRootCertFound = false; } } if (bRootCertFound) { string sUVPriCert = fvMain["RootPublicCert"]; if (sUVPriCert != "") { try { sPubCert = kpMain.toDecryptAES(sUVPriCert); } catch { bRootCertFound = false; } } else { bRootCertFound = false; } } } else { bRootCertFound = false; } if (bRootCertFound) { try { rTool = new RSATool(false); rTool.SetPrivateCert(sPriCert); rTool.SetPublicCert(sPubCert); } catch { bRootCertFound = false; } } if (!bRootCertFound) { fvMain = new FileVar(sFileName); rTool = new RSATool(true); sPubCert = rTool.GetPublicCert(); sPriCert = rTool.GetPrivateCert(); kpMain = new KeyPair(KeyType.AES, sMasterPwd); fvMain["RootPrivateCert"] = kpMain.toAESCipher(sPriCert); fvMain["RootPublicCert"] = kpMain.toAESCipher(sPubCert); } }