Hi!
I have a function library that is used for encrypting and decrypting files written in vb.net and it works fine. HOWEVER i recompiled it in Visual Studio 2005 and recieved a cryptographicexception when I ran FlushFinalBlock(), since I didn't write the function to begin with, I'm a a loss here..
I have a function library that is used for encrypting and decrypting files written in vb.net and it works fine. HOWEVER i recompiled it in Visual Studio 2005 and recieved a cryptographicexception when I ran FlushFinalBlock(), since I didn't write the function to begin with, I'm a a loss here..
Code:
[size=2][color=#0000ff]
Private[/color][/size][size=2][color=#0000ff]Function[/color][/size][size=2] applyCrypto([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] dir [/size][size=2][color=#0000ff]As[/color][/size][size=2] cryptoDirection, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] key [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] inStream [/size][size=2][color=#0000ff]As[/color][/size][size=2] IO.Stream) [/size][size=2][color=#0000ff]As[/color][/size][size=2] MemoryStream[/size]
[size=2][size=2]Dim vector() [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Byte[/color][/size][size=2] = {&H11, &H40, &H18, &HDE, &H48, &H20, &HDE, &H42}[/size]
applyCrypto = [/size][size=2][color=#0000ff]Nothing[/color][/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] outStream [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] MemoryStream([/size][size=2][color=#0000ff]CInt[/color][/size][size=2](inStream.Length))[/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] crStream [/size][size=2][color=#0000ff]As[/color][/size][size=2] CryptoStream = [/size][size=2][color=#0000ff]Nothing
[/color][/size][size=2][color=#008000]'create the Crypto object
[/color][/size][size=2][color=#0000ff]Select[/color][/size][size=2][color=#0000ff]Case[/color][/size][size=2] cMet
[/size][size=2][color=#0000ff]
[/color][/size][size=2][color=#0000ff]Case[/color][/size][size=2] cryptoMethods.TripleDES
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] des [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] TripleDESCryptoServiceProvider()
[/size][size=2][color=#0000ff]If[/color][/size][size=2] dir = cryptoDirection.Encrypt [/size][size=2][color=#0000ff]Then
[/color][/size][size=2]crStream = [/size][size=2][color=#0000ff]New[/color][/size][size=2] CryptoStream(outStream, des.CreateEncryptor(createKey(key), vector), CryptoStreamMode.Write)
[/size][size=2][color=#0000ff]ElseIf[/color][/size][size=2] dir = cryptoDirection.Decrypt [/size][size=2][color=#0000ff]Then
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] decryptor [/size][size=2][color=#0000ff]As[/color][/size][size=2] ICryptoTransform = des.CreateDecryptor(createKey(key), vector)
crStream = [/size][size=2][color=#0000ff]New[/color][/size][size=2] CryptoStream(outStream, decryptor, CryptoStreamMode.Write)
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Select
[/color][/size][size=2][color=#008000]'Write to the crypro stream
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] r [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2] = 0
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] b [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Byte
[/color][/size][size=2][color=#0000ff]While[/color][/size][size=2][color=#0000ff]Not[/color][/size][size=2] r = -1
r = inStream.ReadByte()
[/size][size=2][color=#0000ff]If[/color][/size][size=2] r > -1 [/size][size=2][color=#0000ff]Then
[/color][/size][size=2]b = [/size][size=2][color=#0000ff]CByte[/color][/size][size=2](r)
crStream.WriteByte(b)
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]While
[/color][/size][size=2]crStream.FlushFinalBlock()
applyCrypto = outStream
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Function
[/color][/size]