Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. SignedXml signedXml = new SignedXml(xmldocument);
  2. signedXml.SigningKey = certificado.PrivateKey;
  3. Signature XMLSignature = signedXml.Signature;
  4. Reference reference = new Reference();
  5. reference.Uri = referenciaUri;
  6. XMLSignature.SignedInfo.AddReference(reference);
  7. KeyInfo keyInfo = new KeyInfo();
  8. keyInfo.AddClause(new RSAKeyValue((RSA)certificado.PrivateKey));
  9. keyInfo.AddClause(new KeyInfoX509Data(certificado));
  10. XMLSignature.KeyInfo = keyInfo;
  11. signedXml.ComputeSignature();
  12. XmlElement xmlDigitalSignature = signedXml.GetXml();
  13. xmldocument.DocumentElement.SelectSingleNode(para).AppendChild(xmldocument.ImportNode(xmlDigitalSignature, true));
  14.  
  15. // Base64 encoding
  16. $SignatureValue = rtrim(chunk_split(base64_encode($SignatureValue_bruto), 76));
  17.  
  18. public static string base64_encode(string str)
  19. {
  20. return System.Convert.ToBase64String(Encoding.UTF8.GetBytes(str));
  21. }
  22.  
  23. public static string chunk_split(string str, int len)
  24. {
  25. var strings = new List<string>();
  26. var div = str.Length % len;
  27. var remainder = len - div * len;
  28.  
  29. if (div == 1)
  30. {
  31. return string.Join("", str.Take(len));
  32. }
  33.  
  34. for (var j = 0; j < div; j++)
  35. {
  36. strings.Add(string.Join("", str.Skip(j * len).Take(len)));
  37. }
  38.  
  39. if (remainder > 0)
  40. {
  41. strings.Add(string.Join("", str.Skip(div * len).Take(remainder)));
  42. }
  43.  
  44. return string.Join(Environment.NewLine, strings.ToArray());
  45. }
  46.  
  47. public static string rtrim(string input)
  48. {
  49. return input.TrimEnd(' ');
  50. }
  51.  
  52. chunk_split(base64_encode(strstr), 76);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement