Make streamreader use utf8encoding instead of textbox

Sep 3, 2011 at 3:28 PM
Edited Sep 3, 2011 at 6:51 PM

Hi all.

I have a code that should encrypt a

string using the utf8 encoding of the string.

its working fine, but the encrypting part is using

a 16 bit table in a byte, with utf8, so I guess it won't accept that I

use streamreader/writer should use utf8 instead of plain string.


The problem is as the decrypt/encrypt part:

 Private Shared iv As Byte() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
    Public Shared Function Encrypt(ByVal plain As String, ByVal key As String) As String
        Dim aesenc As ICryptoTransform = aes.CreateEncryptor(utf.GetBytes(key), iv)

        Dim aesenc As ICryptoTransform = aes.CreateEncryptor(utf.GetBytes(key), iv) ------- index is outside the bounds of arrays.


If I increase iv to integer, it says:

Value of type '1-dimensional array of Integer' cannot be converted to '1-dimensional array of Byte' because 'Integer' is not derived from 'Byte'.


If i increase {1-16} to {1-32} it says:

Specified initialization vector (IV) does not match the block size for this algorithm.


I'm trying to do this to the streamreader/writer:
            Catch ex As Exception
                Dim objwriter As New StreamWriter("C:\Users\"(utf8Encoding)
                objwriter.Write(Encrypt(TextBox1.Text, TextBox2.Text, "secret1234"))
                objwriter.WriteLine(Encrypt(TextBox2.Text, TextBox1.Text, "secret1234"))
            End Try
        End If

I guess I have to change the utf.getbyte to integer somehow, or increase iv from 1-16 to 1-32 or higher.

But the problem is still there.