c# - How to edit permissions on CryptoKeySecurity? -
i have posted no luck since have more information thought try again hope can help. reading xml file , verifying fact has been signed. code works when run adminitrator not network service, final line resolves 'true' when not run admin doesnt.
note: not problem reading xml file opens fine. problem 1 of objects in memory. 'think' problem access control lists on cryptokeyrights object.
i have used following (in below code) try , grant access cspparams object:
cryptokeyrights rightsforall = cryptokeyrights.fullcontrol; cryptokeyaccessrule = new cryptokeyaccessrule(@"everyone", cryptokeyrights.fullcontrol, accesscontroltype.allow); cspparams.cryptokeysecurity = new cryptokeysecurity(); cspparams.cryptokeysecurity.addaccessrule(everyone); the above code
the code is:
// verify signature of xml file against asymmetric // algorithm , return result.xmldocument doc, rsa key public static boolean verifylicencefile(string xmllicfilepatharg) { bool isverified = false; try { cspparameters cspparams = new cspparameters(); cspparams.keycontainername = containername; rsacryptoserviceprovider rsakey = new rsacryptoserviceprovider(cspparams); // create new xml document. xmldocument xmldoc = new xmldocument(); // load xml file xmldocument object. xmldoc.preservewhitespace = true; xmldoc.load(xmllicfilepatharg); // check arguments. if (xmldoc == null) throw new argumentexception("doc"); if (rsakey == null) throw new argumentexception("key"); // create new signedxml object , pass // xml document class. signedxml signedxml = new signedxml(xmldoc); // find "signature" node , create new // xmlnodelist object. xmlnodelist nodelist = xmldoc.getelementsbytagname("signature"); // throw exception if no signature found. if (nodelist.count <= 0) { throw new cryptographicexception("verification failed: no signature found in document."); } // example supports 1 signature // entire xml document. throw exception // if more 1 signature found. if (nodelist.count >= 2) { throw new cryptographicexception("verification failed: more 1 signature found document."); } // load first <signature> node. signedxml.loadxml((xmlelement)nodelist[0]); // check signature , return result. isverified = signedxml.checksignature(rsakey); } catch (exception ex) { } return isverified; }
this sounds more permissions on root ca, or signing cert. i'd check certificates in chain in certificate store - if they're in user store (which explain working under administrator) or machine store (where should work everyone)
Comments
Post a Comment