Archive for the 'C#' Category

How to create a key container which is accessible for many users?

Tuesday, September 23rd, 2008

.Net Framework supports a key containers which can be used to store asymmetric keys. Key containers are available for user-level and machine-level store.
User-level RSA key containers are stored with the Windows user profile for a particular user and can be used to encrypt and decrypt information for applications that run under that specific user identity. [...]

How to encrypt a large amount of data using RSA?

Friday, September 19th, 2008

Sometimes we need to encrypt a large amount data using some asymmetric key. As we all know it is impossible to encrypt more bytes than the key size (in bytes) of the key.

Padding
Operating System Supported
Maximum Length of rgb Parameter

OAEP padding (PKCS#1 v2)
Microsoft Windows XP or later.
Modulus size -2 -2*hLen, where hLen is the size of [...]

Sending Data over UDP using UdpClient

Friday, July 4th, 2008

Few days ago I wrote a post how to send data over TCP. Today, I’d like to share a sample how to do it over UDP using UdpClient class. What we cannot do is to keep the state of our connection between sender and receiver. That is because the UDP protocol is stateless. The sender just sends a datagram [...]

Retrieving Type information using Reflection

Thursday, July 3rd, 2008

There are many situations when we need to retrieve part of the information of a type. It can be done via Reflection. This sample uses it to retrieve type’s attributes, fields, properties, methods and constructors. It also sets values to properties and fields and invoke the two custom methods of the class. Fisrst of all we [...]

Getting a Type by full name and creating an instance of it using Activator

Wednesday, July 2nd, 2008

Yesterday was my first work day in my new company. Today I needed to go through a part of components developed by the company. I created a WinForms application with several forms. I used each form to test different controls using different configuration. The application has one main form with buttons - one button per form. Each button’s Text property is set [...]

Sending data over TCP using TcpClient and TcpListener

Tuesday, July 1st, 2008

Sometimes we need to send data via TCP. For this purpose .Net contains two classes - TcpClient and TcpListener.
Let’s assume that we need transfer a list of contacts from a server to client. [Update 07/04/2008: The Contact class is presented in the snippet below. Note that it is decorated with Serializable attribute. It is needed because [...]