| | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Today @ 7:44:49 PM Posts: 1,194, Visits: 3,033 |
| I've built a little utility to see how the TripleDesStream class works, so I can encrypt sensitive strings in source code.
I have a form with:
- textbox to get seed string
- textbox for text to encrypt
- button to encrypt
- textbox with encrypted text
- button to decrypt
- text box with decrypted text
The encrypt code is:
Private Sub btnEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncrypt.Click
Dim seed As String = String.Empty
Dim text As String = String.Empty
' Must have text
If Me.txtTextToEncrypt.Text Is Nothing OrElse Me.txtTextToEncrypt.Text.Trim().Length() = 0 Then
MessageBox.Show("You must provide some text to encrypt!")
Return
End If
' Get text to encrypt
text = Me.txtTextToEncrypt.Text
' Get byte arrays for key and initialization vector
If Not Me.txtSecuritySeed.Text Is Nothing Then
seed = Me.txtSecuritySeed.Text
End If
Dim securityKey As Byte() = SecurityBasics.GetSecurityKey(seed, 24)
Dim initVector As Byte() = SecurityBasics.GetSecurityVector(seed, 8)
' Encrypt
Dim crypto As New TripleDesStream(securityKey, initVector)
Me.txtEncryptedText.Text = crypto.Encrypt(text)
End Sub
This seems to work fine. However, I get an error when I decrypt the text:
Private Sub btnDecrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecrypt.Click
Dim seed As String = String.Empty
Dim text As String = String.Empty
' Must have text
If Me.txtEncryptedText.Text Is Nothing OrElse Me.txtEncryptedText.Text.Trim().Length() = 0 Then
MessageBox.Show("You must provide some text to decrypt!")
Return
End If
' Get text to encrypt
text = Me.txtEncryptedText.Text
' Get byte arrays for key and initialization vector
If Not Me.txtSecuritySeed.Text Is Nothing Then
seed = Me.txtSecuritySeed.Text
End If
Dim securityKey As Byte() = SecurityBasics.GetSecurityKey(seed, 24)
Dim initVector As Byte() = SecurityBasics.GetSecurityVector(seed, 8)
' Encrypt
Dim crypto As New TripleDesStream(securityKey, initVector)
Me.txtDecryptedText.Text = crypto.Decrypt(text)
End Sub
The error is "Invalid character in Base-64 string.
What am I doing wrong? |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: 08/01/2008 8:53:41 AM Posts: 2,671, Visits: 1,879 |
| Ah, the TripleDesStream should be marked as obsolete. It was intended to be used as a replacement for the TripleDesWrapper, but it was never completed. So, you will need to use the TripleDesWrapper instead. There is a sample of how to encrypt fields within the CRM sample distributed with the framework.
www.bungie.net |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: 08/01/2008 8:53:41 AM Posts: 2,671, Visits: 1,879 |
| I believe it's the cust_CreditCard field that is encrypted within the CustomersBO business object in the CRM sample.
www.bungie.net |
| | | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Today @ 7:44:49 PM Posts: 1,194, Visits: 3,033 |
| You should probably update the xml comments for both the TripleDesStream and TripleDesWrapper then. TripleDesWrapper indicates it is marked as obsolete (if you look in object browser) and says to use TripleDesStream instead...hence why I used it 
I'm switching to TripleDesWrapper now though! |
| | | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Today @ 7:44:49 PM Posts: 1,194, Visits: 3,033 |
| | |
|
|