Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Decrypting text encrypted using CBC Blowish in perl using Crypto++
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Troy  
View profile  
 More options Oct 25 2012, 9:30 pm
From: Troy <troy.he...@hixxy.org>
Date: Thu, 25 Oct 2012 18:30:56 -0700 (PDT)
Local: Thurs, Oct 25 2012 9:30 pm
Subject: Decrypting text encrypted using CBC Blowish in perl using Crypto++

Hello,

I have been trying to figure out how to get decrypting of text in perl
working in crypto++ (and possibly the reverse).

#!/usr/bin/perl

use Crypt::CBC;
$iv = "12345678";
$cipher = Crypt::CBC->new( -literal_iv => 1, -literal_key => 1, -key =>
"wowsers ", -iv => $iv, -header => "none");

$plaintext = "my message";

$ciphertext = $cipher->encrypt_hex($plaintext);

$hex_iv = unpack('H*', $iv);

print "$hex_iv$ciphertext\n";

$plaintext = $cipher->decrypt_hex($ciphertext);

print "$plaintext\n";

As per the options enabled in perl, I have disabled all of the default
features and am trying to get it working with a literal key and literal iv
(which is being prepended to the output.

I am then failing to decrypt the message using the following crypto++ code:

    void prepare_key(std::string& key)
    {
      ssize_t len = static_cast<ssize_t>(key.length());
      if (len < Blowfish::MIN_KEYLENGTH)
        key.append(Blowfish::MIN_KEYLENGTH - len, ' ');
      else
      if (len > Blowfish::MAX_KEYLENGTH)
        key.erase(Blowfish::MIN_KEYLENGTH);
      else
      {
        size_t remainder = len % Blowfish::BLOCKSIZE;
        if (remainder) key.append(Blowfish::BLOCKSIZE - remainder, ' ');
      }
    }

    bool encrypt(const std::string& source,
                 std::string& dest,
                 std::string key)
    {
      prepare_key(key);

      AutoSeededRandomPool prng;
      byte iv[Blowfish::BLOCKSIZE];
      prng.GenerateBlock(iv, sizeof(iv));

      dest.clear();
      try
      {
        CBC_Mode<Blowfish>::Encryption e;
        e.SetKeyWithIV(reinterpret_cast<const byte*>(key.c_str()),
key.length(), iv);

        StringSource(source, true,
            new StreamTransformationFilter(e,
                new StringSink(dest)
            )
        );
      }
      catch (const Exception& e)
      {
        return false;
      }

      dest.insert(dest.begin(), std::begin(iv), std::end(iv));

      return true;
    }

    bool decrypt(std::string source, std::string& dest, std::string key)
    {
      prepare_key(key);

      AutoSeededRandomPool prng;
      byte iv[Blowfish::BLOCKSIZE];
      std::memcpy(iv, &source[0], sizeof(iv));
      source.erase(0, sizeof(iv));

      dest.clear();
      try
      {
        CBC_Mode<Blowfish>::Decryption d;
        d.SetKeyWithIV(reinterpret_cast<const byte*>(key.c_str()),
key.length(), iv);

        StringSource(source, true,
            new StreamTransformationFilter(d,
                new StringSink(dest)
            )
        );
      }
      catch (const Exception& e)
      {
        return false;
      }

      return true;
    }  

The crypto++ based encrypt / decrypt functions work fine with eachother. If
I attempt to encrypt the same message as in the perl script with the same
key and iv, the result is different.

Any help much appreciated!
Troy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Troy  
View profile  
 More options Oct 26 2012, 1:30 am
From: Troy <troy.he...@hixxy.org>
Date: Thu, 25 Oct 2012 22:30:04 -0700 (PDT)
Local: Fri, Oct 26 2012 1:30 am
Subject: Re: Decrypting text encrypted using CBC Blowish in perl using Crypto++

Please disregard this, I've made a glaring error in the perl script
omitting the -cipher option, no idea what it uses for default.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »