iTechtalk

Quick Search

Go Advanced

Member Login

Not registered? | Forgot Password
 
Register
Welcome
 
iTechtalk > Tutorials > Programming » Public Key Encryption in VB.NET
Reply
Old 12-04-2008, 10:53 AM   #1 (permalink)
 
jstlanger's Avatar
 
Junior Member
Join Date: Nov 2008
Posts: 13
Default Public Key Encryption in VB.NET

Public key encryption (also termed as asymmetric encryption) has an significant diversity from private key encryption. Public key encryption employs two dissimilar keys: one key for encryption and another key for decryption. Why don’t they merely call this two-key encryption and call private key encryption one-key encryption? While it is widely known that security experts like to create jargon to validate their high consultancy fees, there is also a logical cause for this naming, which lies in the way the two types of encryption are used.

Whereas private key encryption presumes that both the encrypting and decrypting companies already know the private key, public key encryption grants a method to securely issue a key to someone and have that individual send you information that only you can decrypt.

It executes like this: Our system produces a public/private key pair. We send the public key to someone who utilizes it to encrypt a message. He / She send the encrypted message to us, and we decrypt the message with the private key.

Even if an trespasser gains possession of the public key, he cannot exercise it to decrypt the encrypted message because only the private key can decrypt the message, and this is never given away. In distinction with private key encryption, the keys used in public key encryption are more than simple sequences. The key is actually a structure with eight fields: two of the fields are used for encrypting with the public key, and six are used for decrypting with the private key. The public key is obtained by withdrawal from the private key, which is why the private key can be used for both encryption and decryption.

Figure 1-1 demonstrates how public key encryption and decryption work, using the model of a system requesting a credit card number from a user.
Figure :Public key encryption and decryption





Public key encryption is sluggish than private key encryption and cannot process large amounts of data. The RSA algorithm (RSA refers to the initials of the people who developed it: Ron Rivest, Adi Shamir, and Leonard Adleman) can encrypt a message of only 116 bytes (58 unicode characters).

A widespread use for public key encryption is for securely passing a private key, which is then used for encrypting and decrypting other information.
Attach public key encryption to the security library
In this solution, you will add public key encryption functions to your security library.

1. In Visual Studio .NET, open the project CH01_Encryption\EMS\ Start\EMS.sln.

2. Open SecurityLibrary.vb. Add the following code:

3. Namespace PublicKey
Module PublicKey
Function CreateKeyPair() As String
’Create a new random key pair
Dim rsa As New RSACryptoServiceProvider()
CreateKeyPair = rsa.ToXmlString(True)
rsa.Clear()
End Function
Function GetPublicKey(ByVal strPrivateKey As String) As String
’Extract the public key from the
’public/private key pair
Dim rsa As New RSACryptoServiceProvider()
rsa.FromXmlString(strPrivateKey)
Return rsa.ToXmlString(False)
End Function
Function Encrypt(ByVal strPlainText As String, _
ByVal strPublicKey As String) As String
’Encrypt a string using the private or public key
Dim rsa As New RSACryptoServiceProvider()
Dim bytPlainText() As Byte
Dim bytCipherText() As Byte
Dim uEncode As New UnicodeEncoding()
rsa.FromXmlString(strPublicKey)
bytPlainText = uEncode.GetBytes(strPlainText)
bytCipherText = rsa.Encrypt(bytPlainText, False)
Encrypt = Convert.ToBase64String(bytCipherText)
rsa.Clear()
End Function
Function Decrypt(ByVal strCipherText As String, _
ByVal strPrivateKey As String) As String
’Decrypt a string using the private key
Dim rsa As New RSACryptoServiceProvider()
Dim bytPlainText() As Byte
Dim bytCipherText() As Byte
Dim uEncode As New UnicodeEncoding()
rsa.FromXmlString(strPrivateKey)
bytCipherText = Convert.FromBase64String(strCipherText)
bytPlainText = rsa.Decrypt(bytCipherText, False)
Decrypt = uEncode.GetString(bytPlainText)
rsa.Clear()
End Function
End Module
End Namespace
jstlanger is offline   Reply With Quote
 
Reply

Bookmarks

Tags
encryption, public key, vb.net

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to move the public data folder to another drive in Windows SBS 2008? guru4tech Windows server/NT/Work Station 1 05-13-2009 12:20 PM
Add or Remove “Public” Folder icon from the Desktop honcho Windows Vista 0 04-27-2009 07:52 AM
Turn On or Off Bitlocker Drive Encryption reader Windows 7 0 04-13-2009 12:07 PM
Public and private data in C++ Programming kelvin Programming 0 12-01-2008 07:52 AM
BitLocker Drive Encryption in Windows 7 aarzoo Windows 7 0 11-18-2008 10:10 AM


 

Content Relevant URLs by vBSEO 3.3.0