Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cryptography please help

Status
Not open for further replies.

jcisco

Programmer
Sep 17, 2002
125
US
i'm about ready to start pulling out hair here.. i know i doing something really really dumb. can some please point me in the right direction. (i will post my decrypt function but if needed i can post the other.)

private sub decrypt()
dim nByte as Byte() = Convert.FromBase64String(s)
dim a as new System.IO.MemoryStream()
a.Write(nByte, 0, nByte.Length)

dim outputtext as new System.IO.MemoryStream()
dim apple as string ="appleberryappleberryjoh"
dim berry as string ="appleberryappleberrytan"
dim tdesKey(23) as byte
dim tdesIV(23)as byte
dim byteIndex as integer
dim AscEncod as new System.text.ASCIIEncoding()

'encode the keys
AscEncod.GetBytes(apple, byteIndex, apple.Length, tdesKey, byteIndex)
byteIndex = 0
AscEncod.GetBytes(berry, byteIndex, berry.Length, tdesIB, byteIndex)

dim bin(100) as byte
dim rdlen as long = 0
dim totlen as long = a.length
dim len as integer

'dim tdes as new system.Security.Cryptography.TripleDESCryptoServiceProvider()
dim encStream as new System.Security.Cryptography.CryptoStream(outputtext, tdes.CreateDecryptor(tdesKey, tdesIV), Security.Cryptography.CryptoStreamMode.Write)

try
while rdlen < totlen
len = a.Read(bin, 0, 100)
encStream.Write(bin, 0, len)
rdlen = rdlen + len
msgbox (rdlen) 'keep getting a zero here error somewhere above
end while
Finally
encStream.Close()
outputtext.Close()
end try
dim encoded() as byte = outputtext.ToArray()
Me.TextBox1.Text = Convert.ToBase64String(encoded)
s = me.textbox1.text
end sub



thanks for any insight that u can give me.
--------------
:)
 
I haven't looked to closely, but at first glance.... You're writing to a (System.IO.MemoryStream), but you never move back to the start of the stream before trying to read it in again.

a.Seek(0, IO.SeekOrigin.Begin)
while rdlen < totlen
len = a.Read(bin, 0, 100)
encStream.Write(bin, 0, len)
rdlen = rdlen + len
msgbox (rdlen) 'keep getting a zero here error somewhere above
end while
 
thanks u were right that was the cause of my blank memorystream problem. now the problem is that it seems like it's not decrypting correctly. it appears that the correct message is being retrived by bin() byte array, but when i write it to my encStream it is not decrypting the string. i'm just getting garbage for my output string.

suggestions? --------------
:)
 
its' working now thanks for the help. --------------
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top