|
-
May 14th, 2002, 11:51 PM
#1
-
May 15th, 2002, 03:20 AM
#2
Lively Member
Have Fun with this one
I saw this thread and it made me think, so after a few hours I came up with this....
Create a new vb app and add a module, erase all the pre generated code and place this code inside... then on the properties of the form set the "startup object" to point to sub main
Code:
Imports System
Imports System.Text
Imports System.Security.Cryptography
Module Module1
Private RSA As New RSACryptoServiceProvider()
Private KeyInfo As RSAParameters = RSA.ExportParameters(False)
Private AE As ASCIIEncoding = New ASCIIEncoding()
Sub Main()
Dim StrToEncode As String = "This is the text that will be encrypted."
Dim EncodedStr() As Byte ' This is the Array that will hold the Encrypted Data
' Display the Test to be encrypted
MsgBox("String To Be Encrypted:" & vbCrLf & vbCrLf & StrToEncode)
' Encode the Data
EncodedStr = DataEncrypt(StrToEncode)
' Do something with this Encrypted Data
MsgBox("String Encoded:" & vbCrLf & vbCrLf & AE.GetString(EncodedStr) & vbCrLf & vbCrLf)
' Decode the Data
StrToEncode = DataDecrypt(EncodedStr)
'Display the Decrypted String to a Message Box
MsgBox("String Decoded:" & vbCrLf & vbCrLf & StrToEncode)
End Sub
Private Function DataEncrypt(ByVal RawData As String) As Byte()
Dim ByteArray() As Byte = AE.GetBytes(RawData)
DataEncrypt = RSA.Encrypt(ByteArray, False)
End Function
Private Function DataDecrypt(ByVal RawData As Byte()) As String
Dim ByteArray() As Byte = RSA.Decrypt(RawData, False)
DataDecrypt = AE.GetString(ByteArray)
End Function
Private Function GetParamVal(ByVal RawData As Byte()) As String
Dim i As Integer = 0
GetParamVal = "{"
For i = 0 To UBound(RawData)
If i = UBound(RawData) Then
GetParamVal = GetParamVal & RawData(i)
Else
GetParamVal = GetParamVal & RawData(i) & ", "
End If
Next
GetParamVal = GetParamVal & "}"
End Function
End Module
I didn't have the time to write the extra code that needs to save the "KeyInfo" data but I wrote a function that can turn each member of the class into a string for storage just call the GetParamVal function with the KeyInfo.propertyname and it will return the property in a string type, if you wish to access the encrypted data you will need the exact keyinfo data when the string was encrypted.
Hope this helps, if not well at least I learned something about encryption....
-
May 15th, 2002, 10:57 AM
#3
Another thing you could do is use the HashTable class to create your own encryption scheme.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|