Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Weird error with Cryprt::Blowfish and Crypt::DES

by dmorgo (Pilgrim)
on Oct 20, 2004 at 19:48 UTC ( #400965=note: print w/replies, xml ) Need Help??

in reply to Weird error with Cryprt::Blowfish and Crypt::DES

How do you know that $data is exactly 8 bytes long? In other words, exactly what perl code are you using to determine that? Please share that snippet.

It may be the data is exactly 8 characters long, but not 8 bytes. bytes != characters. Maybe the data is encoded in utf8?

If you're reading the data from a file handle, try doing binmode(handle) before reading in the data.

  • Comment on Re: Weird error with Cryprt::Blowfish and Crypt::DES

Replies are listed 'Best First'.
Re^2: Weird error with Cryprt::Blowfish and Crypt::DES
by Beechbone (Friar) on Oct 21, 2004 at 11:36 UTC
    Got it:
    Perl: a7 53 64 81 c6 0a 30 b9 C: c2 a7 53 64 c2 81 c3 86 0a 30 c2 b9
    So the internal strings of Net::SSH::Perl got "infected" with the UTF-8 bit. Seems some of the strings it gets are declared in a "use utf8" area (but are 7bit themselves).

    Now, as what Net::SSH::Perl gives to Cypher::* are binary data (byte strings) regardless of the input strings (character strings), how would I best fix that?

    I see three possibilities:

    1) Fix Net::SHH::Perl to make a difference between character strings it gets and the byte strings it uses to build the SSH protocol in it.

    2) Change our code to disable the UTF8 bit on every string that is given to Net::SSH::Perl.

    3) Change Crypt::* to turn the UTF8 bit off on data that is 8 characters long.

    I'd say #1 would be the cleanest way and #3 the fastest. As we have a deadline of this afternoon for a complete program run, I will implement #3 as a workaround fast. But, what should we do on the long run?

    BTW: Thank you to all who helped, tried to help, or would have helped if they could.


    HELP, How DO I do this? I've got the String as above labeled 'Perl' with UTF8 on. When I just disable the flag, I get the 'bad' String, as labelled with 'C'. So how do I convert that string to a string of 8 bytes with the values as they should be?


    Ok, I found that, too. utf8::downgrade($data);

    Search, Ask, Know
      Thank you soooo much. I worked hours on that problem without finding a reason or solution for that. I read my plaintext string from a xml file and "utf8::downgrade($data);" did the trick.
        Thanks... How to apply the explanation wasn't total clear to me since I was originally try to hack up the to find where the data was being passed incorrectly before I found this thread. Attached is a clear example:
        use utf8; my $username = $connection->{'username'}; my $password = $connection->{'password'}; my $ip = $connection->{'ip'}; chomp( $username , $password , $ip ); utf8::downgrade($username); utf8::downgrade($password); my $ssh = Net::SSH::Perl->new($ip , port => 'ssh' ); $ssh->login($username, $password); my($out, $err) = $ssh->cmd($cmd || "ls -l"); print $out;
        I am having this exact same problem, but don't understand how you implemeneted your fix. Where are you adding 'utf8::downgrade' because when I add it to the data I send as the username to Net::SSH::Perl it sends the data as '1'. I know this is an old thread but hopefully someone will know what I need to do to fix this. Thanks

      Thank you very much for this solution. I had the same issue with "input must be 8 bytes long".

      Strangely enough, I seem to only get this problem when I use strings coming from XML::Simple (XML::Parser), not when I try to run the same commands on CLI or from a different script that also uses Net::SSH::Perl, but gets the parameters from CLI args.

Re^2: Weird error with Cryprt::Blowfish and Crypt::DES
by Beechbone (Friar) on Oct 20, 2004 at 20:48 UTC
    my $d = $data; $d =~ s/(.)/sprintf("%x ", ord($1))/ge; print "data in hex: '$d'\n"
    The data comes from Net::SSH::Perl, I'm not quite sure which part it is when the crypting fails, because there are so many levels of code above it, it's either the login or a command execution (SSH2).

    When I look at aboce's output, I see that it's not the first execution that fails. I haven't counted it, but there have been at least 30 executions before the failing one.

    Search, Ask, Know

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://400965]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2018-07-20 07:11 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (426 votes). Check out past polls.