|
Hi....i am doing chat application.I want to do multilingual application.If a user currently chatting in English and if he selects German then all text should effected into German language.
please help me.
Thanks.
|
|
|
|
|
|
Hello,
How to write simple com service in C# ?
I don't mean just com visible interface - i mean really com service that will start up when the machine will start up automatic and every component could use this component interface as a Com.
|
|
|
|
|
Please refere the MSDN com-service articles.
A DATAPOST COMPUTER CENTRE
(K.V Prajapati)
|
|
|
|
|
Hi,
I am currently developing a client/server application which consists of a "root/master" server, some "normal" servers and some clients.
I want the "root/master" server and the "normal" servers to be securely identified and i want to encrypt traffic between "root/master" server,
"normal" server and clients using Ssl encryption.
Minimum system requirements for servers should be win server 2003 and for clients winXP. (Currently I use win server 2008 for "root/master" server as I got the certificate management working only with the new Certificate Enrollment API)
That's why I need:
- One certificate for the "root/master" server
- One certificate for each "normal" server
- One certificate for each client
-> The certificates of the "root/master" server and the "normal" servers have to be signed by a CA so that I can verify the identity of the servers.
-> The "root/master" server should serve as CA.
This is what I did:
- Create certificate for "root/master" server manually on windows server 2008.
- Imported this certificate manually on the "normal" servers and clients computers.
The "normal" servers and clients can now connect to the "root/master" server using SslStream and identify it.
------------------------------------------------------------------
To get the certificates for the "normal" servers I wanted them to send a certificate request to the "root/master" server.
Then the "root/master" server issues the request and sends certificate back.
I don't want the "normal" server admin to do that. It should automatically be done by the "normal" server when first connecting to the
"root/master" server.
This is what I did:
"Normal" server
...connects to "root/master" server using sslstream and identifies "root/master" server
...sends CommonName for certificate creation
"Root/Master" server (using Certificate Enrollment API)
...creates certificate request
...sends certificate request
...issues certificate request
...get issued certificate and sends it back to "normal" server
Next connection
"Normal" server
...uses issued certificate to "authenticate as client"
-> Problem:
-> The "normal" server does not found the private key for the issued certificate.
-> I looked at the certificate and it has no private key attached. So something went wrong during the certification creation on the "root/master" server.
Has somebody an idea what went wrong during certificate creation?
Is there a general "error" in the process which I designed to let the "normal" servers get their certificates?
------------------------------------------------------------------
Code:
"normal" server
<code>
byte[] cert = this.ReadBytes();
CertManager.CreateCert(cert);
X509Certificate certClient = new X509Certificate2(@"C:\newcert.cer");
</code>
"root/master" Server handling
<code>
String certRequest = CertManagerVista.CreateRequest("CoordClient11");
CertRequest requestObj = CertManagerVista.SendRequest(certRequest);
CertManagerVista.Issue(requestObj);
String cert = CertManagerVista.GetRequestStatus(requestObj);
// cert to bytes
char[] chars = cert.ToCharArray();
int count = chars.Length;
byte[] bytes = new byte[count];
for (int i = 0; i < count; i++)
{
bytes[i] = BitConverter.GetBytes(chars[i])[0];
}
// Send cert
this.SendBytes(bytes);
</code>
CertManagerVista.cs
<code>
static public String CreateRequest(String cn)
{
// Create all the objects that will be required
CX509CertificateRequestPkcs10 objPkcs10 = new CX509CertificateRequestPkcs10Class();
CX509PrivateKey objPrivateKey = new CX509PrivateKeyClass();
CCspInformation objCSP = new CCspInformationClass();
CCspInformations objCSPs = new CCspInformationsClass();
CX500DistinguishedName objDN = new CX500DistinguishedNameClass();
CX509Enrollment objEnroll = new CX509EnrollmentClass();
CObjectIds objObjectIds = new CObjectIdsClass();
CObjectId objObjectId = new CObjectIdClass();
CX509ExtensionKeyUsage objExtensionKeyUsage = new CX509ExtensionKeyUsageClass();
CX509ExtensionEnhancedKeyUsage objX509ExtensionEnhancedKeyUsage = new CX509ExtensionEnhancedKeyUsageClass();
String strRequest = "";
privateKey = "";
try
{
// Initialize the csp object using the desired Cryptograhic Service Provider (CSP)
objCSP.InitializeFromName(
"Microsoft Enhanced Cryptographic Provider v1.0"
);
// Add this CSP object to the CSP collection object
objCSPs.Add(objCSP);
// Provide key container name, key length and key spec to the private key object
//objPrivateKey.ContainerName = "AlejaCMa";
objPrivateKey.Length = 1024;
objPrivateKey.KeySpec = X509KeySpec.XCN_AT_SIGNATURE;
objPrivateKey.KeyUsage = X509PrivateKeyUsageFlags.XCN_NCRYPT_ALLOW_ALL_USAGES;
objPrivateKey.MachineContext = false;
// Provide the CSP collection object (in this case containing only 1 CSP object)
// to the private key object
objPrivateKey.CspInformations = objCSPs;
// Create the actual key pair
objPrivateKey.Create();
//privateKey = objPrivateKey.Export("PRIVATEBLOB", EncodingType.XCN_CRYPT_STRING_BASE64); // did not work
// Initialize the PKCS#10 certificate request object based on the private key.
// Using the context, indicate that this is a user certificate request and don't
// provide a template name
objPkcs10.InitializeFromPrivateKey(
X509CertificateEnrollmentContext.ContextUser,
objPrivateKey,
""
);
// Key Usage Extension
objExtensionKeyUsage.InitializeEncode(
X509KeyUsageFlags.XCN_CERT_DIGITAL_SIGNATURE_KEY_USAGE |
X509KeyUsageFlags.XCN_CERT_NON_REPUDIATION_KEY_USAGE |
X509KeyUsageFlags.XCN_CERT_KEY_ENCIPHERMENT_KEY_USAGE |
X509KeyUsageFlags.XCN_CERT_DATA_ENCIPHERMENT_KEY_USAGE
);
objPkcs10.X509Extensions.Add((CX509Extension)objExtensionKeyUsage);
// Enhanced Key Usage Extension
objObjectId.InitializeFromValue("1.3.6.1.5.5.7.3.2"); // OID for Client Authentication usage
objObjectIds.Add(objObjectId);
objX509ExtensionEnhancedKeyUsage.InitializeEncode(objObjectIds);
objPkcs10.X509Extensions.Add((CX509Extension)objX509ExtensionEnhancedKeyUsage);
// Encode the name in using the Distinguished Name object
objDN.Encode(
"CN=" + cn,
X500NameFlags.XCN_CERT_NAME_STR_NONE
);
// Assing the subject name by using the Distinguished Name object initialized above
objPkcs10.Subject = objDN;
// Create enrollment request
objEnroll.InitializeFromRequest(objPkcs10);
strRequest = objEnroll.CreateRequest(
EncodingType.XCN_CRYPT_STRING_BASE64
);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return strRequest;
}
static public CertRequest SendRequest(String request)
{
// Create all the objects that will be required
CCertConfig objCertConfig = new CCertConfigClass();
CCertRequest objCertRequest = new CCertRequestClass();
string strCAConfig;
string strRequest;
int iDisposition;
string strDisposition;
try
{
strRequest = request;
// Get CA config from UI
strCAConfig = objCertConfig.GetConfig(CC_DEFAULTCONFIG);
//strCAConfig = objCertConfig.GetConfig(CC_UIPICKCONFIG);
// Submit the request
iDisposition = objCertRequest.Submit(
CR_IN_BASE64 | CR_IN_FORMATANY,
strRequest,
null,
strCAConfig
);
// Check the submission status
if (CR_DISP_ISSUED != iDisposition) // Not enrolled
{
strDisposition = objCertRequest.GetDispositionMessage();
if (CR_DISP_UNDER_SUBMISSION == iDisposition) // Pending
{
Console.WriteLine("The submission is pending: " + strDisposition);
return new CertRequest(objCertRequest);
}
else // Failed
{
Console.WriteLine("The submission failed: " + strDisposition);
Console.WriteLine("Last status: " + objCertRequest.GetLastStatus().ToString());
return new CertRequest(objCertRequest);
}
}
//// Get the certificate
//strCert = objCertRequest.GetCertificate(
// CR_OUT_BASE64 | CR_OUT_CHAIN
//);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return new CertRequest(objCertRequest);
}
static public String GetRequestStatus(CertRequest certRequest)
{
CCertRequest objCertRequest = certRequest.request;
CCertConfig objCertConfig = new CCertConfigClass();
String strCAConfig = objCertConfig.GetConfig(CC_DEFAULTCONFIG);
// Refresh the request, since is has now the 'Issued' status
int numDisposition = objCertRequest.RetrievePending(objCertRequest.GetRequestId(), strCAConfig); // Replaced strConfig with ""
// Get the certificate
String certStr = objCertRequest.GetCertificate(CR_OUT_BASE64HEADER);
return certStr;
}
static public void Issue(CertRequest request)
{
CCertAdmin objAdmin = new CCertAdminClass();
CCertConfig objCertConfig = new CCertConfigClass();
String strCAConfig = objCertConfig.GetConfig(CC_DEFAULTCONFIG);
int requestId = request.request.GetRequestId();
// Now issue the request
int numDisposition = objAdmin.ResubmitRequest(strCAConfig, requestId);
}
static public void AcceptPKCS7(String cert)
{
// Create all the objects that will be required
CX509Enrollment objEnroll = new CX509EnrollmentClass();
string strCert;
try
{
strCert = cert;
// Install the certificate
objEnroll.Initialize(X509CertificateEnrollmentContext.ContextUser);
objEnroll.InstallResponse(
InstallResponseRestrictionFlags.AllowUntrustedRoot,
strCert,
EncodingType.XCN_CRYPT_STRING_BASE64,
null
);
Console.WriteLine("Certificate installed!");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
</code>
CertManager.cs
<code>
static public void CreateCert(byte[] data)
{
X509Certificate2 c = new X509Certificate2(data);
FileStream fs = new FileStream(@"C:\newcert.cer", FileMode.Create);
fs.Write(data, 0, data.Length);
fs.Close();
}
</code>
|
|
|
|
|
|
hi guyz i am working on an application of ftp. my application successfully connects to the remote server. the trouble i am dealing with is when i press any key to go(jump) to a specific file my application hangs, but after some time it resumes, i have used key_press_evevt to but not able to getting the logic behind that. so see if any one be able to do it.
|
|
|
|
|
post your code in key_press event
|
|
|
|
|
i do but still not working
|
|
|
|
|
hello there!
i want to save string to file in binary method with C#
it dosent work. 4 example i want to save the string "Hello World" to "myFile.bin" and if i edit this file with notepad i will get this result
וכJ†Ynה’F\$חieֻׁ¥\%ֲ־§
anyone can help with code !!!
|
|
|
|
|
Are you using BinaryWriter???
Post your source code...
|
|
|
|
|
FileStream BinaryFile = new FileStream("c:\\test.dat", FileMode.Create, FileAccess.ReadWrite);
BinaryWriter Writer = new BinaryWriter(BinaryFile);
Writer.Write('a');
Writer.Write(12312);
Writer.Write(456.789);
Writer.Write("test string");
|
|
|
|
|
Try this:
FileStream BinaryFile = new FileStream("c:\\test.dat", FileMode.Create, FileAccess.ReadWrite);
BinaryWriter Writer = new BinaryWriter(BinaryFile);
Writer.Write("hello world");
Writer.Close();
BinaryFile = new FileStream("C:\\test.dat", FileMode.Open , FileAccess.Read);
BinaryReader reader = new BinaryReader (BinaryFile);
Console.WriteLine(reader.ReadString());
Console.ReadLine();
|
|
|
|
|
I have a database with 3 tables: pc, printer, scale. All 3 tables have fileds hostname, ip_address and serial_number. I've designed a form to search any of these tables by host, ip and sn. I'm having trouble making the search go through all 3 tables and return if something is found. Like is i search for host "comp" if it's a pc it returns the values from table pc, if it's a printer returns values from table printer. The same for the other fields.
|
|
|
|
|
Where are you having problems ? It sounds to me like a poor DB design, you probably wanted one table with a column that tells you if it's a PC, a printer, etc. Either way, it sounds like you're saying you can't get the SQL right, which makes this a SQL question. Posting the SQL would sure help us to help you.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
I am trying to get the text from a notepad window.
This is my declaration:
const int WM_GETTEXT = 0x000D;
DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(int _WindowHandler, int _WM_USER, StringBuilder lpstring, int len);
This is what i have for my code:
Process[] p = Process.GetProcessesByName("notepad");
foreach (Process s in p)
{
StringBuilder sb = new StringBuilder(11);
SendMessage(this.Handle.ToInt32(), WM_GETTEXT, sb, 10);
code.Text += sb.ToString();
}
Please explain why my code isn't working so I can learn.
|
|
|
|
|
jdogg4232 wrote: my code isn't working
that doesn't tell us anything. Please describe what works and what doesn't, give the symptoms
(wrong result, hang, exception, ...).
Anyway, I don't understand this.Handle.ToInt32() , that would be asking for your own form's title, which you can read directly from the Form. And why do that for every process?
Probably you need Process.MainWindowHandle
|
|
|
|
|
Sorry i ment to have
Process.Handle.ToInt32()
But when i do it, i do not get anything back, no erors, just empty string.
|
|
|
|
|
jdogg4232 wrote: Process.Handle.ToInt32()
which would be wrong. I suggest you read my earlier reply again.
|
|
|
|
|
This is copy-paste from some old project of mine which uses GETTEXT and it works, I think you might find it useful
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, StringBuilder lParam);
const Int32 WM_GETTEXT = 0xD;
StringBuilder sb = new StringBuilder(256);
SendMessage(hWnd, WM_GETTEXT, (IntPtr)256, sb);
Now as I see it, I would probably change StringBuilder to byte[256] , but StringBuilder works too. 256 is any length you might need. Another thing - if you try to get the text actually typed into notepad, you need to provide the handle of the EDIT window of Notepad, it is different from the process main window (you would get the Notepad caption that way).
Hope it helped, H.
[edit - some typos fixed]
|
|
|
|
|
Hi,
I am a beginner an I want to know how can I make a program start itself as soon as i log on into my PC .(Windows XP SP2 if it makes a difference).
Thanks in advance!
|
|
|
|
|
Daemon[^]
See the section "Windows Equivalent"
|
|
|
|
|
1- In the control panel, there is a Scheduled Tasks item. When configuring the task, there is an option where you can set it to execute at logon.
2- Please post to the right forum next time.
|
|
|
|
|
|
You have 3 options.
1. Use program as services (Must be build correctly for services)
2. Use Registery: (HKLM/HKCU)\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
3. Use shortcut inside START and Look under "ALL PROGRAMS" in Folder Startup
|
|
|
|