StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



How to use the TripleDesStream class?Expand / Collapse
Author
Message
Posted 01/31/2007 11:00:48 AM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame 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?
Post #6468
Posted 02/01/2007 8:36:12 AM


StrataFrame Developer

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
Post #6481
Posted 02/01/2007 8:36:43 AM


StrataFrame Developer

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
Post #6482
Posted 02/01/2007 9:44:38 AM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame 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!
Post #6487
Posted 02/01/2007 9:46:46 AM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP

Group: StrataFrame Users
Last Login: Today @ 7:44:49 PM
Posts: 1,194, Visits: 3,033
That was easy...done!
Post #6488
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 8:02pm

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.062. 9 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.