|
hello,
I am trying to sign data with a CAPICOM.SignedData object.
The SignedData object has got a method called Sign() which performs the operation and this method has got a parameter called Signer which (according to the CAPICOM reference) "must have access to the private key of the certificate used to sign".
I had understood that a public key certificate contains the subject's public key. so, I think that "the private key of the certificate used to sign" means that the certificate does not contain the subject's private key but that is associated with it. My questions are:
1. how is this association?
2. where is stored the private key?
3. how can I obtain a signing private key?
thanks in advance
|
|
|
|
|
Don't use CAPICOM (an interop library). Almost all the functionality of the CryptoAPI is encapsulates in the System.Security.Cryptography namespace and child namespaces and is written to support .NET while using the CAPICOM requires marshalling and isn't always .NET-friendly.
When you sign data, you sign with your private key. This allows the recipient(s) to verify your signature (an encrypted digest of the clear-text, typically) using your public key. RSA uses the same signature and encryption algorithms, where DSA uses different algorithms (more secure).
The private key is maintained soley by the user. It should never be uploaded to a PKI server or be available for others. That would defeat the whole purpose of public key encryption. Only the public key is made public, hence the name.
If you're trying to access your private key, you must provide CSP (cryptographic service provider) information to use a CSP (software-based, smart card, etc.) that contains a private key, as well as how to access that private key.
If you want, see my list of articles (link to them in my sig) for the XML Digital Signatures article. That contains information about using XML signatures and the SignedXml and SignedInfo classes to access your private key in a software-based provider (used by the sn.exe .NET Framework utility app) using the right index into the right key provider.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thank you, Heath.
if i dont use CAPICOM, how can i create a CMS/PKCS#7 (SignedData) structure? I think there is not a PKCS#7 structure in the .NET class library.
ahhh! I think that the response to my question (how is the association between a public-key certificate and the signing private key) was the PKCS#12 structure, wasn't it?
thanks.
|
|
|
|
|
Yes. IIRC, the PKCS12 structure can store more information, but I really haven't worked too much with such types of storage structures. Most references to such structures I see are typically PKCS12, however.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello all,
I currently have a Hashtable that contains a string key and an int value, I am then using this hashtable to populate a combo box using the int value as the combos display value and the key as the combos real value.
The problem I have is that my hashtable values are all ints and I would like this to appear in descending numerical order in the combo.
It seems that the Hashtable does perform some sort of low level ordering as the items do not enumerate out in the same order they were placed into the hashtable. I have tried using sortedlists but the sorting is performed on a string basis, so you end up with something like :
1
11
12
123
1384
22
26
2984
3
I need to use a these types of collections as parts of my code are highly dependant on the .ContainsKey(...) function and the object["keyname"] functionality which is not available on, say, arraylists of simple object arrays.
After spending sometime with google I have had a look at NameObjectCollectionBase and the cp article http://www.codeproject.com/csharp/hashlistarticle.asp[^] but they both seem a little too much for seems like a simple problem
So the question is how can I generate a numerically ordered collection and have the functionality of a Hashtable?
After spending
post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
You pass an IComparer implementation to either the constructor for a list, collection, or dictionary (for those that have such a constructor), or assign it to any supported properties. The Hashtable lets you pass an IComparer implementation to the constructor and allows derivative classes to assign the comparer field.
Read the .NET Framework SDK documentation for the IComparer interface about how the implement it and to see an example (though it's honestly not that hard).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
What you want is a dictionary whose internal structure orders the items by value. The Hashtable performs no ordering. The SortedList performs key ordering. The HashList that was created in the article you referenced performs temporal ordering so it wouldn't help you either. There is no primitive data structure that satisfies this requirement so you'll have to create your own that internally uses both a hashtable and some type of key ordered dictionary for storage. Using both data structures together will give you the ability to order your custom dictionary by value.
When you say that you need to have the functionality of a hashtable did you really mean that a dictionary is sufficient? The reason I ask is because the hashtable is distinquished from other dictionaries because it has O(1) inserts, deletes, and searches. It is impossible to create such a dictionary that is ordered and still performs like a hashtable. If you want your collection ordered by value and to behave like a hashtable then you're out of luck, but to make it behave like a dictionary in general is easy.
I can post an example of this if necessary. But right now it is time to go home!
|
|
|
|
|
Hey,
Today i started working with databases in C#. For the app i'm making i use a premade Access DB. (with tables etc. in it already) With Visual C# 2005 beta i can easaly connect the database to a datagrid. That part works great. But now i want to write new values to the database via input fields. I searched all over the internet to find a good article about it, but i cant find anything usefull Can somebody maybe help me a little?
ps, sorry for my bad english
|
|
|
|
|
|
Thanks for the quick replay
|
|
|
|
|
I'm using a FolderBrowserDialog, which seems to be crashing on full path names with lengths 133 or greater.
I've written a test app that only has a Browse button and a label to display the length of the selected path.
The results are erratic.
With paths of of length 132 characters or less it seems to work ok (i have seen it crash once on 132-length path, though).
At 133, it works sometimes and sometimes not.
At paths of 134 or greater, it crashes almost every single time. Sometimes when you hit the "OK" button in the dialog, sometimes it won't crash until the next time you hit the "Browse" button, sometimes not until you try to close the program.
I have tried different paths all over my system, and 132 seems to be the magic number. Can anyone else duplicate this?
|
|
|
|
|
|
Well that answers that. Thanks Heath.
I'm curious what google query you used, i tried searching before i came here.
|
|
|
|
|
|
FolderBrowserDialog long path
The first search result was on the Microsoft Support site.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
We are building a windows application that needs to look at an .ini file when the program first starts. We have no problem reading the ini file once the app starts up by hard-coding the name of the file, but I would like to be able to dynamically direct the app to the correct ini file when it starts up. Specifically, the main differences between the 2 .ini's would be which database that the app should be using, and whether we are in a test mode or live mode. This would make switching between testing and live use quick, without having to recompile.
So the question is, is there a way to have the properties under the desktop icon be something like "myprogram.exe test.ini" or "myprogram.exe live.ini"
Thanks much for the help...
Alan Berger
|
|
|
|
|
You mean a shortcut? Yes, just type the filename in the Target: field for the shortcut properties after the program. Make sure that Start in: (working directory) field is set to the program directory or the directory where your program looks for files (so for files you access without an absolute file path (start from the drive root), they resolve to this directory). Declare your entry point (Main ) using Main(string[] args) . The filename gets passed as an argument.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
aberger56 wrote:
So the question is, is there a way to have the properties under the desktop icon be something like "myprogram.exe test.ini" or "myprogram.exe live.ini"
In short, yes, your application can take arguments which is why you can write Main as such. I would suggest you look at other options such as extracting the path from a config file.
public static void Main(string[] args)
{
string path = args[0];
if(path != null)
{
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
Heath and Nick:
Thanks very much for your quick and even more importantly, correct, answers. I truly appreciate it!
ab
|
|
|
|
|
Hi all,
I have a program, that is just supposed to open as a server (i.e. listen for connections) and i run it, and it pauses... then i try to move something and the dreaded program not responding error comes up.... I'm new to c# and don't quite understand why this does this. Another side note.. the designer doesnt work now since i added my inner namespace Tito_Network, which handles the networking calls...
here is my code..
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
namespace WindowsApplication4<br />
{<br />
namespace Tito_Network<br />
{<br />
using System;<br />
using System.Text;<br />
using System.Net;<br />
using System.Net.Sockets;<br />
using System.Windows.Forms;<br />
<br />
public class Listen<br />
{<br />
<br />
public Listen(TextBox one, TextBox two) {<br />
IPAddress ip = IPAddress.Parse("127.0.0.1");<br />
TcpListener tcp = new TcpListener(ip,2486);<br />
tcp.Start();<br />
<br />
one.Text +="Server Activated...\n";<br />
<br />
Socket soc_Client = tcp.AcceptSocket();<br />
<br />
try<br />
{<br />
if(soc_Client.Connected)<br />
{<br />
while(true)<br />
{<br />
one.Text +="Client connected from"+soc_Client.AddressFamily;<br />
}<br />
}<br />
}<br />
catch(Exception s)<br />
{<br />
MessageBox.Show(s.ToString());<br />
}<br />
}<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
<br />
public class Form1 : System.Windows.Forms.Form<br />
{<br />
#region Private Form Variables<br />
private System.Windows.Forms.TextBox textBox1;<br />
private System.Windows.Forms.TextBox textBox2;<br />
private System.Windows.Forms.MainMenu mainMenu1;<br />
private System.Windows.Forms.MenuItem menuItem1;<br />
private System.Windows.Forms.MenuItem menuItem2;<br />
private System.Windows.Forms.MenuItem menuItem3;<br />
private System.Windows.Forms.MenuItem menuItem4;<br />
private System.Windows.Forms.MenuItem menuItem5;<br />
private System.ComponentModel.Container components = null;<br />
#endregion <br />
<br />
#region Initialization and Disposal<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if (components != null) <br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
#endregion <br />
<br />
#region Windows Form Designer generated code<br />
private void InitializeComponent()<br />
{<br />
this.textBox1 = new System.Windows.Forms.TextBox();<br />
this.textBox2 = new System.Windows.Forms.TextBox();<br />
this.mainMenu1 = new System.Windows.Forms.MainMenu();<br />
this.menuItem1 = new System.Windows.Forms.MenuItem();<br />
this.menuItem2 = new System.Windows.Forms.MenuItem();<br />
this.menuItem3 = new System.Windows.Forms.MenuItem();<br />
this.menuItem4 = new System.Windows.Forms.MenuItem();<br />
this.menuItem5 = new System.Windows.Forms.MenuItem();<br />
this.SuspendLayout();<br />
this.textBox1.AutoSize = false;<br />
this.textBox1.BackColor = System.Drawing.SystemColors.WindowText;<br />
this.textBox1.ForeColor = System.Drawing.Color.Lime;<br />
this.textBox1.Location = new System.Drawing.Point(16, 184);<br />
this.textBox1.Name = "textBox1";<br />
this.textBox1.ReadOnly = true;<br />
this.textBox1.Size = new System.Drawing.Size(384, 136);<br />
this.textBox1.TabIndex = 0;<br />
this.textBox1.Text = "textBox1";<br />
this.textBox2.AutoSize = false;<br />
this.textBox2.BackColor = System.Drawing.Color.Black;<br />
this.textBox2.ForeColor = System.Drawing.Color.Lime;<br />
this.textBox2.Location = new System.Drawing.Point(472, 184);<br />
this.textBox2.Name = "textBox2";<br />
this.textBox2.ReadOnly = true;<br />
this.textBox2.Size = new System.Drawing.Size(80, 136);<br />
this.textBox2.TabIndex = 1;<br />
this.textBox2.Text = "textBox2";<br />
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {<br />
this.menuItem1,<br />
this.menuItem3});<br />
this.menuItem1.Index = 0;<br />
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {<br />
this.menuItem2});<br />
this.menuItem1.Text = "File";<br />
this.menuItem2.Index = 0;<br />
this.menuItem2.Text = "Quit";<br />
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);<br />
this.menuItem3.Index = 1;<br />
this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {<br />
this.menuItem4,<br />
this.menuItem5});<br />
this.menuItem3.Text = "Connections";<br />
this.menuItem4.Index = 0;<br />
this.menuItem4.Text = "Obtain Clients";<br />
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);<br />
this.menuItem5.Index = 1;<br />
this.menuItem5.Text = "Deactivate Client";<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.ClientSize = new System.Drawing.Size(576, 333);<br />
this.Controls.Add(this.textBox2);<br />
this.Controls.Add(this.textBox1);<br />
this.Menu = this.mainMenu1;<br />
this.Name = "Form1";<br />
this.Text = "Tito v1.0";<br />
this.ResumeLayout(false);<br />
<br />
}<br />
#endregion<br />
<br />
<br />
#region App Main<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new Form1());<br />
}<br />
#endregion<br />
<br />
#region Event Handlers<br />
private void menuItem2_Click(object sender, System.EventArgs e)<br />
{<br />
if(MessageBox.Show("Are you sure you want to quit?","Tito v1.0",<br />
MessageBoxButtons.OKCancel,MessageBoxIcon.Warning)== DialogResult.OK)<br />
{<br />
Application.Exit();<br />
}<br />
}<br />
<br />
<br />
private void menuItem4_Click(object sender, System.EventArgs e)<br />
{<br />
Tito_Network.Listen l = new Tito_Network.Listen(textBox1,textBox2);<br />
}<br />
#endregion <br />
<br />
}<br />
}<br />
<br />
<br />
|
|
|
|
|
AcceptSocket is a blocking call. It will stop execution until a connection is received. This is why you should start a new thread (see the Thread or ThreadPool class in the .NET Framework SDK) to listen for connections so that the UI is not affected.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi, I posted a thread yesterday about thumbnails that I was trying to create that took my PF usage up to an entire gig, well Nick Parker solved my problem, Thanks man.
However, now that that is solved I want to speed up the thumbnails. It takes about 30 seconds to get 64, 5 megapixel pictures resized to be 100,100. The code I'm using is as follows:
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
Bitmap TemporaryBitmap = new Bitmap(ImageFileNames[a]);
ListOfImages.Images.Add(tempBitmap.GetThumbnailImage(100,100,myCallback,IntPtr.Zero));
tempBitmap.Dispose();
TemporaryFilePaths.Add(temps[a]);
It's continually looped to get each picture in the folder and adds them to a List View. Any idea's how I can speed up the time because this will eventually be reading of off flash cards and that'll take even longer. Any help would be greatly appreciated thanks.
|
|
|
|
|
Does specifying the image size of 100, 100 in the TemporyBitmap constructor help?
|
|
|
|
|
No it doesn't, that had been my origonal plan but it did the same thing. There's definitely a way because I've tested several programs and they were able to do it in a matter of seconds. Plus windows is able to create the thumbnails quickly too. I think there has to be some other command that I'm missing.
|
|
|
|
|
Another thought, again untested!
Does using the Image class instead of the Bitmap class for the tempory image help?
|
|
|
|