Assymetric Encryption in Vb .net

sattu

Newcomer
Joined
Mar 30, 2012
Messages
3
Firstly I am completely new to this encryption and public key stuff. I have a Public key (in string format) which I need to use for Assymetric Encryption of my Data using the classes "RSACryptoServiceProvider" and "CspParameters" provided in Vb .Net. I did get lot of examples where they have mentioned regarding what I want, but I got thoroughly confused. My requirement is pretty simple. It is :-

1) I have two string variables say "PublicKey" and "Data". "PublicKey" variable contains the Key I need for encryption.

Code:
Dim PublicKey as String = "KeyValue"
Dim Data as String = "Value To Be Encrypted"

2) Declare an object of "RSACryptoServiceProvider" class and set the "PublicKey" in it. (Maybe using "CspParameters" class)
Code:
Dim ObjRsa as new RSACryptoServiceProvider()
ObjRsa.setPublicKey(PublicKey)  //I know this line doesn't exist, but i want it's equivalent

3) Finally perform the encryption like this:
Code:
Dim EncryptedData as new byte() = ObjRsa.Encrypt(Data)

I was specially confused regarding the setting of "Public key" in either "RSACryptoServiceProvider" or "CspParameters" class objects, in all the examples that I found till date.

I would be extremely glad if someone would guide me regarding this.

Thanks In Advance
 
Back
Top