Thread Datei ver- bzw. entschluesseln mit Crypt::CBC (2 answers)
Opened by styx-cc at 2007-11-26 15:58

styx-cc
 2007-11-26 18:48
#103075 #103075
User since
2006-05-20
533 Artikel
BenutzerIn

user image
Supi, klappt endlich, danke! :-)
Code (perl): (dl )
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
#!/usr/bin/perl
use strict;
use warnings;
use PerlIO::via::CBC;

warn "Not enough arguments, use:\n./aes.pl password de-/encrypt file_name\n" if scalar @ARGV < 3;
my ($password, $action, $file_name) = @ARGV;
start_up($action, $file_name);

sub start_up {
  my $action = shift;
  my $file_name = shift;

  unless (-f $file_name) {
    print "Can't find $file_name.\n";
    exit 0;
  }
  crypto($file_name, $action);
}

sub crypto {
  my $file = shift;
  my $action = shift;
  my $op = $action eq 'encrypt' ? '>' : '<';
  my $suffix = $action eq 'encrypt' ? '.aes' : '';

  PerlIO::via::CBC->config(
    'key'             => $password,
    'cipher'          => 'Rijndael',
  );
  my $fh;
  open($fh, "$op:via(PerlIO::via::CBC)", "$file$suffix");
      if ($action eq 'encrypt') {
        open(SOURCE, '<', $file) or die $!;
          print $fh $_ while(sysread(SOURCE, $_, 1024));
        close SOURCE;
      } else {
        print <$fh>;
      }
  close $fh;
  return 1;
}

Aufruf:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
styx@styx-laptop:~/programmierung/perl/tests$ perl aes.pl pw encrypt aes.pl
styx@styx-laptop:~/programmierung/perl/tests$ perl aes.pl pw decrypt aes.pl.aes
#!/usr/bin/perl
use strict;
use warnings;
use PerlIO::via::CBC;

warn "Not enough arguments, use:\n./aes.pl password de-/encrypt file_name\n" if scalar @ARGV < 3;
.
.
.


Verschluesselt die Datei, entschluesselt sie und gibt sie aus *freu
Pörl.

View full thread Datei ver- bzw. entschluesseln mit Crypt::CBC