Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Simple Encryption Routine VBA to PHP URL Encoding Problem

$
0
0

Hi everyone first time poster here wOOt!

 

Question is about encryption in Visual Basic then dercrypted on PHP Here are my encryption decryption functions they work fine.  The problem is when I pass the base64_encode(encryptedstring) to my web app via parameter string the decryption works mostly well on several smaller strings but longer strings only decrypt halfway!

 

PHP Decrypt:

function php_DecryptValue($cypher,$key){
 // Our output text
 $outText = '';
 
 // Iterate through each character
 for($i=0;$i<strlen($cypher);) // Dont need to increment here
 {
     for($j=0;$j<strlen($key);$j++,$i++)
     {
         $outText .=  $key{$j} ^ $cypher{$i};
     }
 }
 
 return $outText;
}

VB6/VBA Encrypt

Public Function php_EncryptValue(strText As String, strKey As String) As String
'strText length should match strkey length for maximum strength

    Dim i As Integer            'Loop counter
    Dim intKeyChar As Integer   'Character within the key that we'll use to encrypt
    Dim strTemp As String       'Store the encrypted string as it grows
    Dim strChar1 As String * 1  'The first character to XOR
    Dim strChar2 As String * 1  'The second character to XOR
    Dim s

    
    'Loop through each character in the text
    For i = 1 To Len(strText)
        'Get the next character from the text
        strChar1 = Mid(strText, i, 1)
        'Find the current "frame" within the key
        intKeyChar = ((i - 1) Mod Len(strKey)) + 1
        'Get the next character from the key
        strChar2 = Mid(strKey, intKeyChar, 1)
        'Convert the charaters to ASCII, XOR them, and convert to a character again
        strTemp = strTemp & Chr(Asc(strChar1) Xor Asc(strChar2))
    Next i
    
    'Display the resultant encrypted string
    
    php_EncryptValue = strTemp

End Function

So theses algorithms match up fine I encrypt a string in VBA then base64encode it, then urlencode it and pass it to my webapp like this:

 

http://www.MyWebApp.com/index.php?Hash=sdjafkjlsflsaklfjlasjdlfblahblahblah

 

if the string is 300 or so characters it works, when the string is 700-2000 I have issues but I really feel like its a php encoding issue and not with the encryption algorithms.  If I encrypt a string and base encode it my vba app and then paste that value into the decrypt php function i get the string I want.  But when I pass it via URL it goes straight to pot.  I have tried urlencode on the passed string, I've tried rawurlencode / rawurldecode on the string I've tried just base64_encode/base64_decode but nothing is working 100% 

 

Would some php guru kindly point out my mistake? PHP is not my primary language, and I really feel like this is an encoding issue that I'm not seeing clearly.

 

Thanks!

 

David


Viewing all articles
Browse latest Browse all 13200

Trending Articles