crptyohraphy question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 00001144876
    New Member
    • Nov 2009
    • 1

    crptyohraphy question

    I have this source code,

    Code:
    Imports System.IO
    Imports System.Text
    Imports System.Security.Cryptography
    
    Module Module1
    
        Sub Main()
    
    
        End Sub
        Public TheKey(7) As Byte
    
    
        Private Vector() As Byte = {&H12, &H44, &H16, &HEE, &H88, &H15, &HDD, &H41}
    
    
    
        Sub Encrypt(ByVal inName As String, ByVal outName As String)
            Try
                Dim storage(4096) As Byte   'create buffer 
                Dim totalBytesWritten As Long = 8  'Keeps track of bytes written. 
    
                Dim packageSize As Integer   'Specifies the number of bytes written at one time. 
    
                'Declare the file streams. 
                Dim fin As New FileStream(inName, FileMode.Open, FileAccess.Read)
                Dim fout As New FileStream(outName, FileMode.OpenOrCreate, _
                  FileAccess.Write)
                fout.SetLength(0)
    
                Dim totalFileLength As Long = fin.Length  'Specifies the size of the source file. 
    
                'create the Crypto object 
                Dim des As New DESCryptoServiceProvider()
    
                Dim crStream As New CryptoStream(fout, _
                       des.CreateEncryptor(TheKey, Vector), CryptoStreamMode.Write)
    
                'flow the streams 
                    While  totalBytesWritten < totalFileLength 
                    packageSize = fin.Read(storage, 0, 4096)
                    crStream.Write(storage, 0, packageSize)
                    totalBytesWritten = Convert.ToInt32(totalBytesWritten + packageSize / des.BlockSize * des.BlockSize)
                End While
    
                crStream.Close()
    
    
            Catch e As Exception
                MsgBox(e.Message)
            End Try
    
        End Sub
    
        Sub Decrypt(ByVal inName As String, ByVal outName As String)
    
            Try
    
                Dim storage(4096) As Byte
                Dim totalBytesWritten As Long = 8
                Dim packageSize As Integer
                Dim fin As New FileStream(inName, FileMode.Open, FileAccess.Read)
                Dim fout As New FileStream(outName, FileMode.OpenOrCreate, _
                  FileAccess.Write)
                fout.SetLength(0)
                Dim totalFileLength As Long = fin.Length
    
    
                Dim des As New DESCryptoServiceProvider()
                Dim crStream As New CryptoStream(fout, _
                  des.CreateDecryptor(TheKey, Vector), CryptoStreamMode.Write)
    
                Dim ex As Exception
    
                    While  totalBytesWritten < totalFileLength 
                    packageSize = fin.Read(storage, 0, 4096)
                    crStream.Write(storage, 0, packageSize)
                    totalBytesWritten = Convert.ToInt32(totalBytesWritten + packageSize / des.BlockSize * des.BlockSize)
                    Console.WriteLine("Processed {0} bytes, {1} bytes total", packageSize, _
                       totalBytesWritten)
                End While
    
                crStream.Close()
    
            Catch e As Exception
                MsgBox(e.Message & "Please ensure that you are using the correct password")
            End Try
    
        End Sub
    
        Sub CreateKey(ByVal strKey As String)
    
            ' Byte array to hold key 
            Dim arrByte(7) As Byte
    
            Dim AscEncod As New ASCIIEncoding()
            Dim i As Integer = 0
            AscEncod.GetBytes(strKey, i, strKey.Length, arrByte, i)
    
            'Get the hash value of the password 
            Dim hashSha As New SHA1CryptoServiceProvider()
            Dim arrHash() As Byte = hashSha.ComputeHash(arrByte)
    
            'put the hash value into the key 
            For i = 0 To 7
                TheKey(i) = arrHash(i)
            Next i
    
        End Sub
    
    End Module

    and i am getting this error

    Name 'lt' is not declared.
    and
    Character is vaild

    and ideas??
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Visual Studio would have stopped on the line where it has this problem, or the error pallet will tell you the file name and line number where the problem is.

    On that line, you have a variable "It" that you are trying to use, only you have declared it before trying to use it.
    It looks to be in your 'Flow the streams portion &lt

    Comment

    • !NoItAll
      Contributor
      • May 2006
      • 297

      #3
      Try
      Code:
       While  totalBytesWritten < totalFileLength
      This is what happens when you just cut and paste code from a web page. The "<" (less than) symbol gets turned into an HTML entity "&lt;"
      There are two instances of this error that I can see....

      Comment

      Working...