csrzhd has asked for the wisdom of the Perl Monks concerning the following question:

Hi, is it possible to encrypt data with OpenSSL's C API and then decrypt it with Perl module Crypt::CBC?

Replies are listed 'Best First'.
Re: Encrypt in C and decrypt in Perl
by hippo (Archbishop) on Dec 05, 2022 at 09:49 UTC

    In the Examples section of the Crypt::CBC documentation it says:

    Three examples, aes.pl, des.pl and idea.pl can be found in the eg/ subdirectory of the Crypt-CBC distribution. These implement command-line DES and IDEA encryption algorithms using default parameters, and should be compatible with recent versions of OpenSSL.

    This suggests that it is certainly possible. Did you try running those examples? They are probably a good place to start.


    🦛

      Thank you, hippo. It turned out that I was reading the manual of Crypt::CBC of which the version is newer than the package installed in my Linux. Therefore, some features such as SHA-256 key derivation algorithm and -pbkdf=>'pbkdf2' are not available in my system. After removing related codes in my Perl script, it works finally. My C++ application can now decrypt data that was encrypted by Perl script, and vice versa.

        Just a tip for future reference: about halfway down the panel on the left-hand side (on both the module & distribution pages) you'll see a selection list with "Jump to version" — use this to align with whatever version you're working with. This is true for most (if not all) modules; it's not specific to Crypt::CBC.

        — Ken

Re: Encrypt in C and decrypt in Perl
by Anonymous Monk on Dec 04, 2022 at 16:42 UTC
    yes. what code did you try?
      Sorry I'm not native speaker. I can read but am not good at expressing myself in English. I'm desperate to know how to encrypt data in C codes and then decrypt it in Perl code, and vice versa. I've learnt OpenSSL API before, know how to use EVP and BIO but find it very confusing when working with Perl. I cannot find the tutorial or examples on this topic. How and where did you learn it? Thanks.

        No Perl installer that I know of installs the examples. There are two ways I know of to see them: unpack the source archive yourself, or go to the Crypt-CBC distribution on Meta::CPAN.

        Off-topic: I am a native English speaker, and I too have trouble expressing myself in English sometimes.

        Perl is Perl and C is C, no matter what language you speak. Show us your code and we'll show you ours. This is not a code writing service.