Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Encrypt text in perl and decrypt in a windows tool

by asidnayak (Initiate)
on Jun 10, 2010 at 13:30 UTC ( #844000=perlquestion: print w/replies, xml ) Need Help??
asidnayak has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, Requirement: 1)Encrypt a line of text in Perl. 2)Send the encrypted text in a mail body. 3)Recipient needs to decrypt the text using ant decryption tool in Windows. What I tried: I used Crypt::Blowfish module to encrypt the line of text and send it as part of the mail body. I copied and pasted the encrypted text from the mail body to a free tool "CryptoLab". But the decrypted result doesn't match with the original text. Please advice.
  • Comment on Encrypt text in perl and decrypt in a windows tool

Replies are listed 'Best First'.
Re: Encrypt text in perl and decrypt in a windows tool
by jettero (Monsignor) on Jun 10, 2010 at 13:42 UTC
    Normally you wouldn't use Crypt::Blowfish directly. Choose Crypt::CBC and make sure to use binmode where necessary. Most likely you forgot a bunch of sticky little details like padding and initialization vectors and things. Let CBC do the work:
    my $cipher = Crypt::CBC->new(-key => 'my secret key', -cipher => 'Blow +fish'); my $crypted = $cipher->encrypt("blarg!!"); my $text = $cipher->decrypt($crypted); # blarg
      Below is my code: -----------------------
      use Crypt::CBC; use Crypt::Blowfish; my $key = "abcdefghijlmnopqrstuvwxyz"; my $cipher = Crypt::CBC->new( -key => "$key", -cipher => 'Blowfish', ); my $ciphertext = $cipher->encrypt("3769-198501-21002"); my $plaintext = $cipher->decrypt($ciphertext); print "$key\n"; print "$ciphertext\n"; print "$plaintext\n";
      ------------------------------ The value of "$ciphertext" is send as part of mail body. I want to decrypt the value of "$ciphertext" using a Windows based tool. Please advice
        I really don't think the platform matters at all. This just isn't a "windows" vs. "<platform of choice>" question. Basically, it sounds to me like you need to parse the email body and feed it to encrypt()/decrypt(). You're either going to need to figure how how to do that (see perlretut and Mail::Box and things like that); or try to get a co-worker to do it. If you're looking for a windows specific tool (other than Perl I guess), this just isn't the right site.

        UPDATE: It sounds like you don't need Perl, you need a windows email tool. This just isn't a Perl question I guess.

Re: Encrypt text in perl and decrypt in a windows tool
by marto (Archbishop) on Jun 10, 2010 at 13:41 UTC

    Have you tried writing a short script to decrypt your encrypted text? Perhaps posting your code would help.

    An alternative to using another tool (CryptoLab), you could package such a script (and any modules you use) using pp so that your target machine wouldn't need to have an installation of Perl, or the modules you use in order to decrypt.

Re: Encrypt text in perl and decrypt in a windows tool
by hemanth.damecharla (Initiate) on Jun 12, 2010 at 07:55 UTC

    From the crytolab page Note: The block ciphers implemented for CryptoLab use ECB mode instead of the more common CBC mode used for encryption. It is known that ECB mode is much less secure than other modes of operation.

    So, using Crypt::CBC is not an option as the generated cipher is always going to be different. I tried using Crypt::ECB module but that did not yield the desired results. Maybe, setting a different keysize might help

    Their developer page might have some information as to how random keys are generated from given passwords (read cipher keys).

    use Crypt::ECB; use Crypt::Blowfish; my $key = shift or die "Usage crypt_ecb_bf <keytoencrypt>\n"; my $crypt = Crypt::ECB->new; $crypt->padding(PADDING_AUTO); $crypt->cipher('Blowfish') || die $crypt->errstring; $crypt->key("$key"); my $ciphertext = $crypt->encrypt_hex("Hello World!"); #since cryptolab +s is outputting hex my $plaintext = $crypt->decrypt_hex($ciphertext); print "$key\n"; print "$ciphertext\n"; print "$plaintext\n";
    Hope is a Heuristic Search.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://844000]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2018-04-24 23:14 GMT
Find Nodes?
    Voting Booth?