Tag: security

Microsoft.Office.Interop是否可以安全地用于(文件转换)网站?

我正在编写一个关于女巫用户必须添加报告(Word文档)的网站,并且可以查看它们我将* .doc转换为* .pdf,然后通过pdf.js显示它们。 对于转换我使用Microsoft.Office.Interop.Word。 代码看起来像 public void ConvertDocument(string PATH) { FileInfo FILE = new FileInfo(PATH); if (FILE.Extension.ToLower() == “.doc” || FILE.Extension.ToLower() == “.docx” || FILE.Extension.ToLower() == “.docm” || FILE.Extension.ToLower() == “.dotx” || FILE.Extension.ToLower() == “.dotm”) { if (FILE.Length == 0) { return; } object oMissing = System.Reflection.Missing.Value; Word.Application word = new Word.Application(); try { word.Visible […]

无法解密RSA加密密钥

长话短说,我正在使用DES而我正在使用RSA加密密码进行密钥交换,密码不超过16个字符问题是当我加密密钥时,加密的大小对我来说太大了解密这里是我的rsa加密和解密代码: 加密: – 我一直在尝试将localpwd作为“asd” byte[] plaintext = utf8.GetBytes(localpwd); byte[] ciphertext = rsaservice.Encrypt(plaintext, false); string cipherresult = Convert.ToBase64String(ciphertext); 然后我打印文本框上的加密密钥并尝试解密 byte[] ciphertext = utf8.GetBytes(filetest.Text); byte[] plain = rsaservice.Decrypt(ciphertext, true); string plaintext = utf8.GetString(plain); 我得到“要解密的数据超过这个256字节模数的最大值”。 我尝试增加密钥大小,以便能够加密和解密更大的密钥大小,但增加密钥只会增加加密数据的大小导致相同的错误,请帮助!

如何防止MSIL运行时注入?

如此处所示的程序化MSIL注入或此处http://www.codeproject.com/Articles/463508/NET-CLR-Injection-Modify-IL-Code-during-Run-time您可以使用一些棘手的注入在运行时修改IL代码。 我的问题是:如何预防? 例如,如果有人使用它来绕过安全function,我该如何避免安全漏洞?

为什么我不能在C#中设置此ACL规则?

在Vista SP1上作为提升管理员运行,我的C#应用​​程序尝试使用以下代码设置以下规则。 不会产生错误,但目录的ACL上也没有任何更改。 我错过了什么? public static void Main( string args[] ) { string dirPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), “Company”), “Product” ); Directory.Create(dirPath); _SetAcl(dirPath, “Users”, FileSystemRights.FullControl); } private static void _SetAcl(string path, string identity, FileSystemRights rights) { var info = new DirectoryInfo(path); var acl = info.GetAccessControl(); var rule1 = new FileSystemAccessRule(identity, rights, AccessControlType.Allow); bool modified; acl.ModifyAccessRule(AccessControlModification.Reset, rule1, out […]

检查Windows服务状态 – 我需要什么权限

我想在不同的远程服务器上检查一些Windows服务状态,如下所示: ServiceController sc = new ServiceController(“MyWindowsService”, “COMPUTER_NAME”); var status = sc.Status 但我不(也不能)在这些服务器上拥有管理员权限。 我应该要求检查状态的权利是什么? 我也不想重启它们,我只需要Read access, 应用程序未在同一台计算机上运行。

如何为ECDiffieHellmanCng导出私钥

我正在尝试从ECDiffieHellmanCng对象的新实例导出密钥,以便稍后可以使用相同的密钥创建它的实例。 但是在尝试导出它时出现错误。 //Create new ECDiffieHellmanCng which automatically creates new keys var ecdh = new ECDiffieHellmanCng(); //Export the keys var privateKey = ecdh.Key.Export(CngKeyBlobFormat.EccPrivateBlob); 当我使用消息“ 不支持请求的操作 ”调用Export方法时,我收到CryptographicException 。在代码中放入一些断点后,它甚至在执行方法之前抛出了exception。 查看Export方法的定义,它使用SecuritySafeCriticalAttribute进行装饰,因此我怀疑此属性实际上是在抛出exception。 导致此exception的原因是什么? 如何保存密钥以便以后可以创建相同ECDiffieHellmanCng对象的实例?

获取.NET应用程序的当前/活动安全区域?

我有一个行为奇怪的应用程序,只是为了validation,我想看看它当前正在运行的安全区域。 我找到了System.Security.SecurityZone枚举,但似乎无法找到任何会返回我正在运行的内容。 有人有任何提示吗? 基本上我想知道我的应用程序是在MyComputer,Intranet,Internet,Untrusted,Trusted等运行。 编辑:这是我编写的用于查找此代码的次要测试应用程序,感谢@blowdart 。 using System; using System.Reflection; namespace zone_check { class Program { static void Main(string[] args) { Console.WriteLine(“.NET version: ” + Environment.Version); foreach (Object ev in Assembly.GetExecutingAssembly().Evidence) { if (ev is System.Security.Policy.Zone) { System.Security.Policy.Zone zone = (System.Security.Policy.Zone)ev; Console.WriteLine(“Security zone: ” + zone.SecurityZone); break; } } } } }

SecurityAttribute.Unrestricted问题

我对此属性感到困惑,如此处所述, http://msdn.microsoft.com/en-us/library/system.security.permissions.securityattribute.unrestricted.aspx我们可以将其全部或非完整。 我的困惑是直接理解的许可,应该只有两个状态 – 授予和不授予,完整和非完整意味着什么?

授予远程用户(非管理员)使用WMI和C#在命名空间cimv2中枚举Win32_Service中的服务的能力

我正在创建一个监视狗服务,它将监视各种远程服务器上的其他服务(所有服务都位于同一个域中)。 我用来连接远程服务器的用户不是管理员。 当我尝试枚举Win32_Service类中的服务时,我得到一个拒绝访问错误。 我已将用户的“远程启用”和“启用帐户”权限提供给WMI控件中的Root \ CIMV2命名空间。 我可以使用以下代码连接到服务器。 对象ServiceListItem只是一个包含服务器名称和服务名称的简单类: SecureString secureString = new SecureString(); foreach ( char c in “password” ) { secureString.AppendChar( c ); } ConnectionOptions connectionOptions = new ConnectionOptions(); connectionOptions.Username = “domain\\user”; connectionOptions.SecurePassword = secureString; foreach ( ServiceListItem service in _serviceList ) { ManagementScope managementScope = new ManagementScope(); managementScope = new ManagementScope( String.Format( @”\\{0}\root\cimv2″, […]

在C#中以编程方式将证书和私钥转换为.PFX

我有一个成功的LetsEncrypt证书请求的.cer文件输出。 我有原始私钥用于为LetsEncrypt创建证书签名请求(CSR)。 现在我们需要使用.NET以编程方式将这两个文件组合成一个用于IIS的PFX包 由于我们试图以编程方式执行此操作pvk2pfx不实用,我们希望尽可能避免使用openssl。 为了演示,我们尝试复制此function,但使用CS .NET而不是pvk2pfx:pvk2pfx.exe -pvk Server.pvk -spc Server.cer -pfx Server.pfx 我已经详尽地研究过了,这里有我看到的可能性: 一种方法似乎是使用X509Certificate2,如: // Import the certficate X509Certificate2 cert = new X509Certificate2(“c:\\cert.cer”); // Import the private key X509Certificate2 cert = new X509Certificate2(“c:\\key.pvk”); // Or import the private key – Alternative method X509DecryptString(token, @”c:\CA.pvk”, “mypassword”); // Export the PFX file certificate.Export(X509ContentType.Pfx, “YourPassword”); File.WriteAllBytes(@”C:\YourCert.pfx”, certificateData); 这里有一些其他的方法,但所有这些方法似乎省略了关于私钥的部分或他们需要pvk2pfx.exe […]