is there anyway that I can convert this to use RSA encryption? im kinda new to VB.Net and even worse at encryption. thanks
Imports System.Text
Imports System.Security.Cryptography
Imports System.IO
Public Class ClsEncryption
Public Shared Function DESEncrypt(ByVal Data As String, ByVal Key As String) As String
Dim DES As New System.Security.Cryptography.DESCryptoServiceProvider
Dim dHash As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim encrypted As String = ""
Try
Dim hash(7) As Byte
Dim temp As Byte() = dHash.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(Key))
Array.Copy(temp, 0, hash, 0, 8)
DES.Key = hash
DES.Mode = Security.Cryptography.CipherMode.ECB
Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = DES.CreateEncryptor
Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
Return encrypted
Catch ex As Exception
End Try
End Function
End Class
For encryption you could pass the (trusted) public key instead of the DES key to the function. You could keep the encryption the same as the it is now, but instead of using the now replaced DES key, you should generate this key using a random number generator. Then you can encrypt the DES key using PKCS#1 v1.5 padding. Finally, you require some kind of container format to send the encrypted DES key and the ciphertext.
To decrypt, use the private key of the asymmetric key pair to decrypt the DES key, and then perform the decryption of the plain text as it is now.
Note that you should use an IV, should not use DES or ECB mode encryption, ASCII is better replaced by UTF-8 etc. etc. If this is for a project of any importance, ask for expert help. If possible, find out a library function to do all this for you, e.g. something that creates PKCS#7/CMS EncryptedData structures.