How do I encrypt and decrypt data in Perl

Encryption and decryption in Perl can be accomplished using cryptography modules like `Crypt::CBC` and `Crypt::OpenSSL::AES`. Below, you'll find an example that demonstrates how to encrypt and decrypt data using these modules.

#!/usr/bin/perl use strict; use warnings; use Crypt::CBC; use MIME::Base64; # Create a new cipher my $key = 'This is a key123'; # Key must be 16 characters for AES-128 my $cipher = Crypt::CBC->new(-key => $key, -cipher => 'Crypt::OpenSSL::AES'); # Data to encrypt my $data = "Hello, World!"; # Encrypt the data my $encrypted = $cipher->encrypt($data); my $encoded_encrypted = encode_base64($encrypted); print "Encrypted and Base64 Encoded: $encoded_encrypted\n"; # Decrypt the data my $decrypted = $cipher->decrypt(decode_base64($encoded_encrypted)); print "Decrypted: $decrypted\n";

Perl Encryption Data Security Crypt::CBC Cryptography AES Encryption