use Module::Load::Conditional qw[can_load check_install requires]; $Module::Load::Conditional::VERBOSE = 1; my $crypt_mods = {'Crypt::CBC' => undef, 'Crypt::Blowfish' => undef, 'Digest::SHA1' => undef, 'MIME::Base64' => undef, 'Compress::Zlib' => undef, 'Crypt::DH' => undef}; if (( can_load(modules=> {'Math::BigInt::GMP' => undef}, verbose => 1) || can_load(modules=> {'Math::BigInt' => undef}, verbose => 1)) && can_load(modules => $crypt_mods, verbose => 1)) { $encryption_avail = 1; } print $encryption_avail ? "All required crypto modules found and loaded: Encryption available\n" : "Encryption disabled: required modules not found\n"; #### sub decrypt { my ($message, $cipher, $key) = @_; my ($plaintext, $comptext, $ciphertext, $armortext, $cbc); $cbc = Crypt::CBC->new( -key => $key, -cipher => $cipher); $armortext = $$message; $ciphertext = decode_base64($armortext) || out ("Unarmor failed!"); $comptext = $cbc->decrypt($ciphertext) || out ("Decrypt failed!"); $plaintext = Compress::Zlib::memGunzip($comptext) || out ("Decompress failed!"); $$message = $plaintext; return (1); } #### use Module::Loaded; foreach my $mk ('Compress::Zlib', 'Crypt::Blowfish', 'Crypt::CBC', 'Crypt::DH', 'Digest::SHA1', 'Math::BigInt::GMP', 'Math::BigInt', 'MIME::Base64') { mark_as_loaded($mk); } #### All required crypto modules found and loaded: Encryption available 'Compress::Zlib' already marked as loaded ('/usr/lib/perl5/5.10.0/i686-linux-thread-multi-64int-ld/Compress/Zlib.pm') at ./icbm.conditional-load line 225 'Crypt::Blowfish' already marked as loaded ('/usr/lib/perl5/site_perl/5.10.0/i686-linux-thread-multi-64int-ld/Crypt/Blowfish.pm') at ./icbm.conditional-load line 225 'Crypt::CBC' already marked as loaded ('/usr/lib/perl5/site_perl/5.10.0/Crypt/CBC.pm') at ./icbm.conditional-load line 225 'Crypt::DH' already marked as loaded ('/usr/lib/perl5/site_perl/5.10.0/Crypt/DH.pm') at ./icbm.conditional-load line 225 'Digest::SHA1' already marked as loaded ('/usr/lib/perl5/site_perl/5.10.0/i686-linux-thread-multi-64int-ld/Digest/SHA1.pm') at ./icbm.conditional-load line 225 'Math::BigInt::GMP' already marked as loaded ('/usr/lib/perl5/site_perl/5.10.0/i686-linux-thread-multi-64int-ld/Math/BigInt/GMP.pm') at ./icbm.conditional-load line 225 'Math::BigInt' already marked as loaded ('/usr/lib/perl5/5.10.0/Math/BigInt.pm') at ./icbm.conditional-load line 225 'MIME::Base64' already marked as loaded ('/usr/lib/perl5/5.10.0/i686-linux-thread-multi-64int-ld/MIME/Base64.pm') at ./icbm.conditional-load line 225