Greetings, monks.

I was writing an instant messaging client for fun, which would encrypt messages with gpg before sending them across the network using netcat (there are likely better ways of doing this than netcat, but it's the one I'm used to). However, when I try to encrypt my message, I get the response:

wrong response from gnupg (expected SHM_INFO): at ./pchat line (I marked the line below)

It's my understanding that the GPG module expects filenames as arguments for the messages to encrypt, and where to save the result, and it returns SHM_INFO upon file-not-found errors. I thought I could use local variables as if they were files by passing them in like \$varname, but this appears not to be working correctly.

Any help would be greatly appreciated. Thanks!

#!/usr/bin/env perl use warnings; use strict; use Term::ReadKey; # For the noecho use GnuPG qw( :algo ); # From the GnuPG CPAN page if( $ARGV != 2 ) { die "Usage: pchat <host> <port>"; } client( $ARGV[0], $ARGV[1] ); sub client { my $target = shift; my $port = shift; print "Who do I encrypt to: "; my $keyname = <STDIN>; chomp( $keyname ); ReadMode('noecho'); print "PGP Key passphrase (not echoed): "; my $passphrase = <STDIN>; chomp $passphrase; print "\n"; # The user's return key won't be echoed ReadMode(0); # Reset term status open (my $net, "|-", "nc $target $port") or die "Can't open ne +tcat!"; while( 0 == 0 ) { my $message = encrypt( $keyname, $passphrase ); last if $message eq "exit"; print $message . "\n"; # Here's where I'm _going_ to send the message via net +cat. # I haven't done it yet, I want to just get the encryp +tion working first. } close $net; print "Connection Terminated.\n"; } sub encrypt { my $gpg = new GnuPG() or die "Cannot open gpg!"; my $keyname = shift; my $passphrase = shift; print "Message: "; my $message = <STDIN>; chomp( $message ); return "exit" if( length($message) == 0 ); # Quit if blank mes +sage $message . "\n" . chr(04); # Tack on a return and EOF, so this + looks like a file to GPG my $encrypted_message = ""; $gpg->encrypt( recipient => $keyname, plaintext => \$message, +output => \$encrypted_message, sign => 1, passphrase => $passphrase, +armor => 1 ) or die "Error encrypting: $!"; # The above is the line I'm getting errors on. return $encrypted_message; }

In reply to Perl GPG Chat by riven

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.