[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

String Encryption & Decryption

Hi all

I want to use Crypt::Blowfish to encrypt my cookies I cant seem to figure it out.

I want to encrypt:

$CookieName = "Some_Name_123";

$CookieValue = "Some_Value_123";

And then of course in need an example to decrypt them. I need a simple working sample.

0
blnukem
Asked:
blnukem
  • 3
  • 2
1 Solution
 
Adam314Commented:
use Crypt::Blowfish;

$CookieName = "Some_Name_123";
$CookieValue = "Some_Value_123";

my $key = "SomeKeyHere";
my $cipher = new Crypt::Blowfish $key;
my $CookieName_Crypt = $cipher->encrypt($CookieName);
my $CookieValue_Crypt  = $cipher->encrypt($CookieValue);

my $CookieName_Plain = $cipher->decrypt($CookieName_Crypt);
my $CookieValue_Plain = $cipher->decrypt($CookieValue_Crypt)
0
 
blnukemAuthor Commented:

Adam314

That doesn't seem to work for me.
0
 
Adam314Commented:
What part of it doesn't work?  Do you get an error message?  Is the data just not correct?

It looks like there are some invalid characters in your original code, which i copied/pasted.  Did you remove them:
$CookieName = "Some_Name_123";
$CookieValue = "Some_Value_123";
0
 
blnukemAuthor Commented:

Adam314

Q: it looks like there are some invalid characters in your original code, which i copied/pasted.  Did you remove them:

A: Yes

I run the code as above and get ERROR: input must be 8 bytes long.
0
 
Adam314Commented:
Your input ($CookieName, $CookieValue) must all be exactly 8 bytes long.

If you want to encrypt/decrypt data of arbitrary length, look at Crypt::CBC
http://search.cpan.org/~lds/Crypt-CBC-2.22/CBC.pm


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now