owlclown has asked for the wisdom of the Perl Monks concerning the following question:

Hi folks, I have a problem with the functional use of Crypt::RC4. I can encrypt and decrypt text, but once I have the plaintext from the decryption I have only binary data. For example, with this code:
#!/usr/bin/perl use CGI qw(:all); use Crypt::RC4; use strict; my $encrypted = param("encrypted"); my $decrypted = RC4($encrypted,"mykey"); print "Content-Type: text/html\n\n"; print "<b>Encrypted Data: $encrypted</b><br><br>"; print "<b>Decrypted Data: $decrypted</b><br><br>";
I get a value of "¡4Ï$²M%®4¬õDšê«˜H" for $decrypted. The value of $encrypted is "ÖäbŸ€ U)ÐÀ&$", which was sent to me through a GET query, encoded as: "%A0%D6%E4b%9F%80%09U%29%D0%C0%26%1A%24". The actual value of $decrypted should, in some way, end up being "This is a test". I've tried simple stuff like MIME::Base64, but I'm pretty much ending up clueless on this. If I go straight through with a regular perl script, with everything done inside, such as this:
my $encrypted = RC4("thisisatest",'This is a test'); my $decrypted = RC4("thisisatest",$encrypted);
Then the value of $decrypted is proper ASCII. I suspect that part of the problem may be that the encryption operation is taking place on a seperate system that I have no control over running Windows 2k and IIS, with encryption taking place with Visual Basic. Could it be that the two systems use a different output format and I have to do some kind of conversion?

Oh, please, grant me the wisdom,

--
Owlclown
"You can cage the singer but not the song."
-- Harry Belafonte

Replies are listed 'Best First'.
Re: Converting binary from Crypt::RC4
by Zaxo (Archbishop) on Jan 14, 2003 at 15:55 UTC

    You have reversed the argument order in RC4(): my $decrypted = RC4("mykey",$encrypted);

    After Compline,
    Zaxo

      Okay. I guess you stare at something long enough you start to believe it. Thanks a million, and I'm going to go hit myself over the head with a baseball bat a few times. -- Owlclown "You can cage the singer but not the song." -- Harry Belafonte