I have a blowfish class that I found on planet source code I believe. I am encrypting a string that is being sent to my server. Then trying to decrypt the string from the data arrvial and I keep getting an error. I'm not sure what is going on or what I am doing wrong. It works great encrypting and decrypting in a text box but for some reason it's not working through winsock. Maybe someone can help me figure this out.
This is the code I have in my client connect event.
Dim crypt As clsBlowFish
Set crypt = New clsBlowFish
Dim strPrivate As String
Dim strUser As String, strUserEncrypted As String
strPrivate = "aDq&s3kUsvVKNm-dRCF2-XJC%5j&%hL5*S5=bu%ZFLsc2D2"
Call crypt.BlowFish(strPrivate)
Call crypt.StringEncrypt(txtUsername.Text, strUserEncrypted)
sOCk.SendData Chr(&H1) & "ENTER" & strUserEncrypted & "CHAT"
On the server side I have this in my data arrival
Dim crypt As clsBlowFish
Set crypt = New clsBlowFish
Dim strPrivate As String
Dim strEncrypted as string, strDecrypted as string
strPrivate = "aDq&s3kUsvVKNm-dRCF2-XJC%5j&%hL5*S5=bu%ZFLsc2D2"
sOCk.GetData strData, vbString
strEncrypted = strData
Call crypt.BlowFish(strPrivate)
Call crypt.StringDecrypt(strEncrypted, strDecrypted)
As soon as the client connects and the server gets the data it gives me an error saying
Run-time error '-2147218101(80040d4b)':
String to decrypt should be sized divisible by 8
The data being sent seems to be working fine. I've displayed the encrypted text in a messagebox before its being sent and it shows as if its encrypted then I sniff the packet as its being sent and its also encrypted so the problem is on the server side.
I've used this same exact code using textboxes to encrypt and decrypt and it worked perfect but sending over winsock doesn't seem to work. Maybe I'm not receiving the data correctly?
Edit: Thanks Remy Lebeau
I fixed it by encrypting all of the text like so.
Call crypt.StringEncrypt(Chr(&H1) & "ENTER" & txtUsername.Text & "CHAT", strUserEncrypted)