J'ai posté à ce sujet déjà mais pas de chance depuis lors j'ai plus d'informations j'ai pensé que j'essaierais encore j'espère vraiment que quelqu'un peut aider. Fondamentalement, je lis un fichier XML et vérifie le fait qu'il a été signé. Ce code fonctionne parfaitement lorsqu'il est exécuté en tant qu'administrateur mais pas en tant que service réseau, la ligne finale se résout à 'vrai' mais lorsqu'il n'est pas exécuté en tant qu'administrateur ne le fait pas.Comment modifier les autorisations sur CryptoKeySecurity?
REMARQUE: ce n'est pas un problème avec la lecture du fichier XML, cela ouvre très bien. Le problème est avec l'un des objets en mémoire. Je pense que le problème est de faire avec les listes de contrôle d'accès sur l'objet CryptoKeyRights.
Je l'ai utilisé les éléments suivants (dans le code ci-dessous) pour essayer de donner à chacun l'accès à l'objet CspParams:
CryptoKeyRights rightsForall = CryptoKeyRights.FullControl;
CryptoKeyAccessRule everyone = new CryptoKeyAccessRule(@"Everyone", CryptoKeyRights.FullControl, AccessControlType.Allow);
cspParams.CryptoKeySecurity = new CryptoKeySecurity();
cspParams.CryptoKeySecurity.AddAccessRule(everyone);
Le code ci-dessus
Le code est:
// Verify the signature of an XML file against an asymmetric
// algorithm and return the 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 a new XML document.
XmlDocument xmlDoc = new XmlDocument();
// Load an XML file into the 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 a new SignedXml object and pass it
// the XML document class.
SignedXml signedXml = new SignedXml(xmlDoc);
// Find the "Signature" node and create a new
// XmlNodeList object.
XmlNodeList nodeList = xmlDoc.GetElementsByTagName("Signature");
// Throw an exception if no signature was found.
if (nodeList.Count <= 0)
{
throw new CryptographicException("Verification failed: No Signature was found in the document.");
}
// This example only supports one signature for
// the entire XML document. Throw an exception
// if more than one signature was found.
if (nodeList.Count >= 2)
{
throw new CryptographicException("Verification failed: More that one signature was found for the document.");
}
// Load the first <signature> node.
signedXml.LoadXml((XmlElement)nodeList[0]);
// Check the signature and return the result.
isVerified = signedXml.CheckSignature(rsaKey);
}
catch (Exception ex)
{
}
return isVerified;
}