in reply to Re^3: Crypt::SMIME Trouble
in thread Crypt::SMIME Trouble

Good idea, but I'm on Linux and not on Windows! So linebreaks are \n instead of \r\n.

In the original example for the module line 16 looked like this: $smime->setPrivateKey($privkey, $crt);
In my example I made this out of it: $smime->setPrivateKey(<PKEY>, <CERT>);

Do you think <PKEY> and <CERT> could be the reason for my mess?

Replies are listed 'Best First'.
Re^5: Crypt::SMIME Trouble
by Corion (Patriarch) on Nov 30, 2010 at 11:58 UTC

    <PKEY> will only read one line from the file, or, in list context (as you have it there), read all lines as lists. Unless you have no line endings in your files, this is likely not what you want. I recommend reading the file into a variable first, inspecting the variable for correctness, and then passing on the variable to ->setPrivateKey.

      Yay! With the code below it worked:

      #!/usr/bin/perl use Crypt::SMIME; open(PKEY, "/home/alice/ssltestkey.pem") || die "open failed: $!"; open(CERT, "/home/alice/ssltestcert.pem") || die "open failed: $!"; my $plain = <<'EOF'; From: alice@example.org To: bob@example.org Subject: Crypt::SMIME test his is a test mail. Please ignore... EOF my $privkey = do { local $/; <PKEY> }; my $crt = do { local $/; <CERT>}; my $smime = Crypt::SMIME->new(); $smime->setPrivateKey($privkey, $crt); my $signed = $smime->sign($plain); print $signed;

      Thank you andal, Corion, sundialsvc4 for your suggestions!