|
Sorry, I was not aware of XmlWriter, yes you can read up the MSDN article on XmlWriter class and I think, it is best suited for your purpose.
|
|
|
|
|
Hello, i would like to sign a xml document using a certificate stored in my machine. I have been looking for examples but in all of them framework 1.1 is used (using Microsoft.Web.Services.Security) and altough i have it, i cannot use it with Microsoft Visual Studio .NET 2002. It is possible to make the Microsoft Visual Studio to use the 1.1 version of the framework??
I only need the signed xml document to make some testing, so if it isn´t possible to sign with 1.0 using my own certificate, please tell me a program that do that (not infopath because if i check the signature always false is returned).
About the signature...it must be xmldsig.
I have a very near deadline to give my project so if you help me i will be very grateful!
Regards!
|
|
|
|
|
Read my article, XML Digital Signatures for Application Licensing[^]. It uses the classes in the .NET BCL for xmldsig. Many people - including my first work that lead to this article - use Microsoft.Web.Services.dll assembly because the documentation for the the BCL assemblies isn't so great - but it is possible. It just requires some digging into the IL in the System.Security.dll assembly.
Microsoft.Web.Services.dll, BTW, is actually from the Web Service Enhancements, or WSE. There are two versions - 1.0 and 2.0. You can read about the WSE at http://msdn.microsoft.com/webservices/building/wse/[^]. WSE 1.0 will work with both .NET 1.0 and 1.1.
Software Design Engineer
Developer Division Sustained Engineering, Microsoft
My Articles
|
|
|
|
|
I have read your article and i have used your method to sign and to check the signature.
When you sign you don´t add the certificate info, so i add it in order to get it in the server when he receives it.
To perform the signature, it works, but when i verify it...the checksignature method always returns false...i have tried millions of things and none works.
Here i show you some code to sign:
<br />
<br />
Microsoft.Web.Services.Security.X509.X509Certificat cert;<br />
<br />
XmlDocument doc = new XmlDocument();<br />
doc.Load("c:/Formtosign.xml");<br />
<br />
SignedXml sxml = new SignedXml(doc);<br />
sxml.SigningKey = cert.key; <br />
<br />
sxml.SignedInfo.CanonicalizationMethod =<br />
SignedXml.XmlDsigCanonicalizationUrl;
<br />
Reference r = new Reference("");<br />
<br />
r.AddTransform(new XmlDsigEnvelopedSignatureTransform(false));<br />
<br />
sxml.AddReference(r);<br />
<br />
System.Security.Cryptography.Xml.KeyInfo keyInfo = <br />
new System.Security.Cryptography.Xml.KeyInfo(); <br />
<br />
keyInfo.AddClause(new System.Security.Cryptography.Xml.KeyInfoX509Data(cert)); <br />
sxml.KeyInfo = keyInfo; <br />
<br />
sxml.ComputeSignature();<br />
<br />
XmlElement sig = sxml.GetXml();<br />
doc.DocumentElement.AppendChild(sig);<br />
<br />
XmlTextWriter writer = new XmlTextWriter<br />
("c:/Formsigned.xml",System.Text.Encoding.UTF8);<br />
writer.Formatting = Formatting.Indented;<br />
<br />
try<br />
{<br />
doc.WriteTo(writer);<br />
}<br />
finally<br />
{<br />
writer.Flush();<br />
writer.Close();<br />
}<br />
Now the code to verify the signature;
<br />
nodeList = doc.GetElementsByTagName<br />
("Signature",SignedXml.XmlDsigNamespaceUrl);<br />
<br />
nodeList2 = doc.GetElementsByTagName("X509Certificate");<br />
<br />
SignedXml[] signatures = new SignedXml[nodeList.Count];<br />
<br />
validSignatures = nodeList.Count;<br />
<br />
<br />
for(int i = 0; i < nodeList.Count; i++)<br />
{<br />
signatures[i] = new SignedXml();<br />
signatures[i].LoadXml((XmlElement)nodeList[i]);<br />
<br />
<br />
Certificate cerCapi = new CertificateClass();<br />
cerCapi.Import(nodeList2[i].InnerText);<br />
ICertContext iCertCntxt = (ICertContext) cerCapi;<br />
int certcntxt = iCertCntxt.CertContext ;<br />
IntPtr hCertCntxt = new IntPtr(certcntxt);<br />
<br />
Microsoft.Web.Services.Security.X509.X509Certificate cer = new Microsoft.Web.Services.Security.X509.X509Certificate(hCerCntx);<br />
<br />
<br />
RSACryptoServiceProvider csp = new RSACryptoServiceProvider();<br />
csp = (RSACryptoServiceProvider)cer.PublicKey;<br />
if (!signatures[i].CheckSignature(csp))<br />
validSignatures--;<br />
}<br />
Your method is adapted to my necesities...but i think that is nearly the same. I get the keys not from a program, I get them from the certificate.
Thank you in advance...
|
|
|
|
|
URL:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfusingforeachwithcollections.asp
Hi! I have created a class library in C# using IEnumerable interface as specified in above URL, Example 2.
Now, I am iterating the items from Visual basic but it is giving error like Object does not support this property or method while it works fine with .net. As mentioned in URL, it should work with the VB also.
What can be the problem?
C# code is same as in URL, Example 2.
Here is the VB code:
Dim col As New MyCollection
Dim i As Object
For Each i In col
MsgBox (i)
Next
|
|
|
|
|
Ami Shah wrote:
am iterating the items from Visual basic but it is giving error like Object does not support this property or method while it works fine with .net.
Do you mean Visual Basic 6? I wouldn't think that a class written with C# would work in VB6 without a lot of extra work (I believe it is possible via COM, but it takes a lot to achieve it)
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
Ya, Visual Basic 6 only. It is mentioned in the given URL also that you can use For Each statement in Visual Basic 6 also with using Example code 2.
I have implemented the same code given in Example 2 only and Calling loop thru VB as mentioned. It should work acoording to article, right?
|
|
|
|
|
I wouldn't think that is possible. You need to be using VB.NET
I understand that is possible to access .NET objects in a non .NET environment via a COM interface, but I've never tried. However, that solution will not give you access to the enumerator via a foreach statement, you would use the via the methods exposed via the IEnumerable interfave directly.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
See the URL, in the example 2 it is clearly written that
"This example repeats the same algorithm of Example 1, but uses a generic collection that can be enumerated from other languages such as Visual Basic."
I think the meaning is that We can use the for each and iterate thru collection from visual basic.
|
|
|
|
|
Given the context of the article, they are meaning Visual Basic.NET. By "other languages" it looks to me that they mean other languages that use the .NET framework.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
|
I've made an Interface IDataFactory with a property ISqlDbComponent{get;set;}
a component with the interface IDataFactory:
public class DataFactory : System.ComponentModel.Component, IDataFactory
The property should be visible with
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
but isn't.
When I derive a component from DataFactory, the property ISqlDbComponent IS visible.
I don't understand why and which Designer Attribute I have to add to the property to make it visible in the first implementation and not only in derived classes.
The property is implemented in the component "DataFactory" so why it isn't visible in the designer?
Thanks a lot
Stefan
|
|
|
|
|
STW wrote:
The property should be visible with
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
but isn't.
Thats not true. That controls what the designer 'saves', and that attribute means it will be saved.
Look at BrowsableAttribute, but public Properties are visible by default.
top secret xacc-ide 0.0.1
|
|
|
|
|
Thanks for reply.
Yes, right.
I forgot to mention that I set [Browsable(true)] for the property.
Is there anything else?
Stefan
|
|
|
|
|
I'm inserting data into a text log file. I need to delete only certain lines of data, generally from line 50 to the end (EOF). I then need to write data to the same file starting at line 50.
Q. How do I delete certain lines of data???
Q. How do I delete from a certain line of data the EOF???
Q. How do I start writing at a specific line???
|
|
|
|
|
1. read each line into an arraylist, then delete the lines u dont need, then write to file again.
2. there is only one EOF and thats at the end-of-file.
3. see 1
top secret xacc-ide 0.0.1
|
|
|
|
|
Hy everyone!
I designed a windows Form which contains a control by default.
Now I do want to add another control depending on the data, meaning if the data contains ínfos which have to be displayed in the control then the control should be inserted, the Form size is changed etc. (if the length where the data is stored is not 0)
I managed to check if the data needs the second form and I changed the Forms size, but at the moment I am not sure how to insert the second control dynamicaly. I can't just throw it in like I did with the otherone and let the code being insert automaticaly.
So I do want to do something like
if(data.secondform.length!=0)<br />
{<br />
resize Form<br />
insert second control<br />
display data in the control<br />
}
the other way round shouldn't be the problem meaning removing the control again when I do get data which is not asking for the control.
Could anyone of you please tell me what I do have to do to insert the control in my Forms windows? (maybe with some code statements)
Thanks!
Stephan.
|
|
|
|
|
check
http://support.microsoft.com/default.aspx?scid=kb;EN-US;319266
Sanjay Sansanwal
www.sansanwal.com
|
|
|
|
|
is this the same for Windows.Controls?
Meaning could I use the button for example as a sample for my task?
Thanks!
Stephan.
|
|
|
|
|
The Form class in System.Windows.Forms namespace contains a Controls property which is a collection of controls. It has methods to add and remove controls, among others. Check it out on MSDN.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Here is one possible approach:
in start of program:
object Item = GetData();
...cast Item to specific type...
in your data component:
public object GetData()
{
...read the data and determine the different types of data
...now cast that data to the specific type of data
...and return that type-specific object
}
public class DataTypeOne
{ .. what makes this unique .. }
public class DataTypeTwo
{ .. what makes this unique .. }
in your form
InitializeComponents();
LoadForm(TypeSpecificItem);
...
public void LoadForm(DataTypeOne item)
{
DataOneForm form = new DataOneForm(item);
this.Components.Add(form);
}
public void LoadForm(DataTypeTwo item)
{
DataTwoForm form = new DataTwoForm(item);
this.Components.Add(form);
}
.... overload for each object type ....
This signature left intentionally blank
|
|
|
|
|
How i write a program. It can control IE6 like back,home, choose a specify link in website. Do you some information to develop it
Nothing
|
|
|
|
|
Have a look at
http://www.codeproject.com/csharp/webbrowser.asp
store your internet favourites online - www.my-faves.co.uk
|
|
|
|
|
|
Sorry, I posted that comment from Mozilla and for some reason I don't get the Clickety option in that.
store your internet favourites online - www.my-faves.co.uk
|
|
|
|