Leser: 5
![]() |
![]() |
5 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/perl
use strict;
use warnings;
use Crypt::Rijndael;
use Digest::MD5 qw/md5_hex/;
my $password = $ARGV[0] || 1;
my $cipher = Crypt::Rijndael->new(md5_hex($password), Crypt::Rijndael::MODE_CBC() );
print decrypt( encrypt('testtesttesttest') );
sub encrypt {
my $plain = shift;
#$plain must be a multiple of 16 (in bytes)
my $crypted = $cipher->encrypt($plain);
return $crypted;
}
sub decrypt {
my $crypted = shift;
my $plain = $cipher->decrypt($crypted);
return $plain;
}
Quotehttp://search.cpan.org/~bdfoy/Crypt-Rijndael-1.05/...keysize
Returns the keysize, which is 32 (bytes). The Rijndael cipher actually supports keylengths of 16, 24 or 32 bytes, but there is no way to communicate this to Crypt::CBC.
QuoteWhen the last block of plaintext is shorter than the block size, it must be padded. Padding methods include: "standard" (i.e., PKCS#5), "oneandzeroes", "space", and "null".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/bin/perl use strict; use warnings; use Crypt::CBC; use Digest::MD5 qw/md5_hex/; my $password = $ARGV[0] || 1; my $cipher = Crypt::CBC->new(-key => md5_hex($password), -cipher => 'Rijndael'); print decrypt( encrypt('gfg') ); sub encrypt { my $plain = shift; #$plain must be a multiple of 16 (in bytes) my $crypted = $cipher->encrypt($plain); return $crypted; } sub decrypt { my $crypted = shift; my $plain = $cipher->decrypt($crypted); return $plain; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl
use strict;
use warnings;
use Crypt::CBC;
use Digest::MD5 qw/md5_hex/;
warn "Not enough arguments, use\naes.txt <pass> <file> <de-/encrypt>\n" if scalar @ARGV < 3;
my ($password, $file_name, $action) = @ARGV;
start_up($action, 0, $file_name);
sub start_up {
my $action = shift;
my $clean_up = shift;
my $file_name = shift;
my $is_file = -f $file_name ? 1 : 0;
return unless $is_file;
$action = $action eq 'e' ? 'encrypting' : 'decrypting';
crypto($file_name, $clean_up, $action);
}
sub crypto {
my $file = shift;
my $clean_up = shift;
my $action = shift;
my $suffix = $action eq 'encrypting' ? 'aes' : 'no';
my $cipher = Crypt::CBC->new(-key => md5_hex($password),
-cipher => 'Rijndael');
my $buffer;
my $buffer_size = 1024;
print "Begin $action $file...";
$cipher->start($action);
open(SOURCEFILE, $file) or die $!;
open DESTFILE, '>', "$file.$suffix" or die $!;
while (sysread(SOURCEFILE,$buffer,$buffer_size)) {
$buffer = $cipher->crypt($buffer);
print DESTFILE $buffer;
}
close DESTFILE;
close SOURCEFILE or die $!;
$cipher->finish;
print " done!\n";
if ($clean_up) {
#...
}
return 1;
}
perl crypt.pl passwort file e
1
2
3
4
5
6
7
8
9
10
open SOURCEFILE, '<', $file or die $!;
open DESTFILE, '>', "$file.$suffix" or die $!;
$cipher->start($action);
while ( read(SOURCEFILE, $buffer, $buffer_size) ) {
$buffer = $cipher->crypt($buffer);
syswrite(DESTFILE, $buffer, $buffer_size);
}
syswrite(DESTFILE, $cipher->finish, $buffer_size);
close DESTFILE;
close SOURCEFILE or die $!;
![]() |
![]() |
5 Einträge, 1 Seite |