in reply to Multimedia file encryption : Crypt::CBC or Crypt::Rijndael
#!/usr/bin/perl use warnings; use strict; use Crypt::Rijndael; # keys must be 128, 192 or 256 "bits" long, # 8 bits in a letter, so 8 x 16 = 128 #my $key = 'abcdefgghjkloiuy'; #128 bits or 8 x 16 my $key = 'abcdefgghjkloiuyabcdefgghjkloiuy'; #256 bits or 8 x 32 print "key->$key\n"; my $plaintext= "adrqwqqqqqqqqqqqqqqqqqqqqqqwrxcq4gfq3g2q45g2q43g5"; print "plaintext->$plaintext\n"; my $plaintext16= get16($plaintext); print "plaintext16->$plaintext16\n"; my $cbc = new Crypt::Rijndael $key, Crypt::Rijndael::MODE_CBC; my $crypted = $cbc->encrypt($plaintext16); print 'crypted->',"$crypted\n"; #keep encrypted string in different pr +int string #to avoid character corruption of prec +eding string my $cbc1 = new Crypt::Rijndael $key, Crypt::Rijndael::MODE_CBC; my $decrypted = $cbc1->decrypt($crypted); print "decrypted->$decrypted\n"; #this sub makes all data blocksize of 16 bytes. sub get16 { my $data = shift; return $data . "\0" x ( 16 - length($data)%16 ); } exit; #You can also use this to get data that is in a multiple of 16 bytes: # this requires $username < 16 bytes and prefix packs with spaces # sprintf '%16s', $username; #or you can xor it # $filecrypted = $cipher->encrypt($file^("\0"x16)); #To strip any padding after decryption: #my $plaintext = $cipher->decrypt($secret_stuff); # $plaintext =~ s/^\0+//; # remove leading null bytes, use \s (not \0) for spaces
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Multimedia file encryption : Crypt::CBC or Crypt::Rijndael
by ikegami (Patriarch) on Nov 15, 2010 at 00:53 UTC | |
by sundeep (Acolyte) on Nov 16, 2010 at 06:36 UTC |