Installingacertificateina.MSIcustomactiondoesn'twork行动。证书已安装,但当我使用它查询AWS时出现此错误:对象仅包含密钥对的公共部分。还必须提供私钥。安装程序正在升级并以WindowsVista为目标。如果我使用单独的.exe安装完全相同的证书,使用完全相同的代码,它就可以工作。那么使用WindowsInstaller安装证书有什么区别呢?持久键集);X509Storestore=newX509Store(StoreName.My,StoreLocation.LocalMachine);store.Open(OpenFlags.ReadWrite);商店。添加(证书);商店。关闭();}catch(Exceptionex){thrownewDataException("Certificateappearedtoloadsuccessfullybutalsoseemstobenull.",ex);}}else{thrownewException("没有足够的权限安装证书");好吧,至少这个问题为我赢得了翻转徽章......原来证书是安装的密钥文件权限。我必须授予所有用户读取权限。这是我用来授予所有(本地)用户读取权限的代码:以上是C#学习教程:InstallingCertificatesin.MSICustomActionsDoesn'tWork更多关于C#学习教程,希望大家多多关注对它—privatestaticvoidAddAccessToCertificate(X509Certificate2cert){RSACryptoServiceProviderrsa=cert.PrivateKeyasRSACryptoServiceProvider;如果(rsa==null)返回;字符串keyfilepath=FindKeyLocation(Unirsa.CspKeyContainer;KeyInfo.Name)FileInfofile=newFileInfo(System.IO.Path.Combine(keyfilepath,rsa.CspKeyContainerInfo.UniqueKeyContainerName));文件安全fs=file.GetAccessControl();SecurityIdentifiersid=newSecurityIdentifier(WellKnownSidType.BuiltinUsersSid,null);fs.AddAccessRule(newFileSystemAccessRule(sid,FileSystemRights.Read,AccessControlType.Allow));文件.SetAccessControl(fs);}privatestaticstringFindKeyLocation(stringkeyFileName){stringpathCommAppData=System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),@"MicrosoftCryptoRSAMachineKeys");string[]textArray=Directory.GetFiles(pathCommAppData,keyFileName);如果(textArray.Length>0)返回pathCommAppData;字符串pathAppData=System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),@"MicrosoftCryptoRSA");textArray=Directory.GetDirectories(pathAppData);如果(textArray.Length>0){foreach(stringstrintextArray){textArray=Directory.GetFiles(str,keyFileName);如果(textArray.Length!=0)返回str;}}return"私钥存在但不可访问";}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
