﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Role Based Security  » How to use the TripleDesStream class?</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 11:51:31 GMT</lastBuildDate><ttl>20</ttl><item><title>How to use the TripleDesStream class?</title><link>http://forum.strataframe.net/FindPost6468.aspx</link><description>I've built a little utility to see how the TripleDesStream class works, so I can encrypt sensitive strings in source code.  &lt;br&gt;
&lt;br&gt;
I have a form with:&lt;br&gt;
&lt;br&gt;
- textbox to get seed string&lt;br&gt;
&lt;br&gt;
- textbox for text to encrypt&lt;br&gt;
&lt;br&gt;
- button to encrypt&lt;br&gt;
&lt;br&gt;
- textbox with encrypted text&lt;br&gt;
&lt;br&gt;
- button to decrypt&lt;br&gt;
&lt;br&gt;
- text box with decrypted text&lt;br&gt;
&lt;br&gt;
The encrypt code is:&lt;br&gt;
&lt;br&gt;
[codesnippet] Private Sub btnEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncrypt.Click&lt;br&gt;
    Dim seed As String = String.Empty&lt;br&gt;
    Dim text As String = String.Empty&lt;br&gt;
&lt;br&gt;
    ' Must have text&lt;br&gt;
    If Me.txtTextToEncrypt.Text Is Nothing OrElse Me.txtTextToEncrypt.Text.Trim().Length() = 0 Then&lt;br&gt;
      MessageBox.Show("You must provide some text to encrypt!")&lt;br&gt;
      Return&lt;br&gt;
    End If&lt;br&gt;
&lt;br&gt;
    ' Get text to encrypt&lt;br&gt;
    text = Me.txtTextToEncrypt.Text&lt;br&gt;
&lt;br&gt;
    ' Get byte arrays for key and initialization vector&lt;br&gt;
    If Not Me.txtSecuritySeed.Text Is Nothing Then&lt;br&gt;
      seed = Me.txtSecuritySeed.Text&lt;br&gt;
    End If&lt;br&gt;
    Dim securityKey As Byte() = SecurityBasics.GetSecurityKey(seed, 24)&lt;br&gt;
    Dim initVector As Byte() = SecurityBasics.GetSecurityVector(seed, 8)&lt;br&gt;
&lt;br&gt;
    ' Encrypt&lt;br&gt;
    Dim crypto As New TripleDesStream(securityKey, initVector)&lt;br&gt;
    Me.txtEncryptedText.Text = crypto.Encrypt(text)&lt;br&gt;
  End Sub&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
This seems to work fine. However, I get an error when I decrypt the text:&lt;br&gt;
&lt;br&gt;
[codesnippet]  Private Sub btnDecrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecrypt.Click&lt;br&gt;
    Dim seed As String = String.Empty&lt;br&gt;
    Dim text As String = String.Empty&lt;br&gt;
&lt;br&gt;
    ' Must have text&lt;br&gt;
    If Me.txtEncryptedText.Text Is Nothing OrElse Me.txtEncryptedText.Text.Trim().Length() = 0 Then&lt;br&gt;
      MessageBox.Show("You must provide some text to decrypt!")&lt;br&gt;
      Return&lt;br&gt;
    End If&lt;br&gt;
&lt;br&gt;
    ' Get text to encrypt&lt;br&gt;
    text = Me.txtEncryptedText.Text&lt;br&gt;
&lt;br&gt;
    ' Get byte arrays for key and initialization vector&lt;br&gt;
    If Not Me.txtSecuritySeed.Text Is Nothing Then&lt;br&gt;
      seed = Me.txtSecuritySeed.Text&lt;br&gt;
    End If&lt;br&gt;
    Dim securityKey As Byte() = SecurityBasics.GetSecurityKey(seed, 24)&lt;br&gt;
    Dim initVector As Byte() = SecurityBasics.GetSecurityVector(seed, 8)&lt;br&gt;
&lt;br&gt;
    ' Encrypt&lt;br&gt;
    Dim crypto As New TripleDesStream(securityKey, initVector)&lt;br&gt;
    Me.txtDecryptedText.Text = crypto.Decrypt(text)&lt;br&gt;
  End Sub&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
The error is "Invalid character in Base-64 string.  &lt;br&gt;
&lt;br&gt;
What am I doing wrong?</description><pubDate>Thu, 01 Feb 2007 09:46:46 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: How to use the TripleDesStream class?</title><link>http://forum.strataframe.net/FindPost6488.aspx</link><description>That was easy...done!</description><pubDate>Thu, 01 Feb 2007 09:46:46 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: How to use the TripleDesStream class?</title><link>http://forum.strataframe.net/FindPost6487.aspx</link><description>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  :ermm:&lt;br&gt;
&lt;br&gt;
I'm switching to TripleDesWrapper now though!  ;)</description><pubDate>Thu, 01 Feb 2007 09:44:38 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: How to use the TripleDesStream class?</title><link>http://forum.strataframe.net/FindPost6482.aspx</link><description>I believe it's the cust_CreditCard field that is encrypted within the CustomersBO business object in the CRM sample.</description><pubDate>Thu, 01 Feb 2007 08:36:43 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: How to use the TripleDesStream class?</title><link>http://forum.strataframe.net/FindPost6481.aspx</link><description>Ah, the TripleDesStream should be marked as obsolete.&amp;nbsp;&amp;nbsp;It was intended to be used as a replacement for the TripleDesWrapper, but it was never completed.&amp;nbsp; So, you will need to use the TripleDesWrapper instead.&amp;nbsp; There is a sample of how to encrypt fields within the CRM sample distributed with the framework.</description><pubDate>Thu, 01 Feb 2007 08:36:12 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item></channel></rss>