Chinaunix首页 | 论坛 | 博客
  • 博客访问: 466506
  • 博文数量: 279
  • 博客积分: 4467
  • 博客等级: 上校
  • 技术积分: 2830
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-03 14:43
文章分类

全部博文(279)

文章存档

2013年(1)

2012年(39)

2011年(35)

2009年(29)

2008年(131)

2007年(44)

分类:

2008-07-02 11:51:02

1. genkey.pl

Description:
It will use the username to create a system account and
generate the private and public key file in home directory eg.
useradd -m
and
GnuPG perl module to generate a pair of public and private key


2. encrypt.pl
gpg -r --output --encrypt

Description:
used to encrypt the file with username's public key when user upload
file via web frontend and put the result file in home directory

3. decrypt.pl file path>
gpg --secret-keyring -o --decrypt
--passphrase-fd

Description:
used to decrypt encrypted file in server with user provided keyring and
password when user click download the file via web frontend. The keyring
is protected with the password which same as system user password.

 

#!/usr/bin/perl

use GnuPG;
$username=$ARGV[0];
$email=$ARGV[1];
$size=@ARGV;
if($size!=2){
print "usage: gen_key.pl \n";
exit(0);
}
#$username="admin11";

#$email='seven.zhang@uniforce.net';


#system "/var/www/html/sstg/bin/create_account.pl $username";

#system "create_account.pl $username";


my $gpg = new GnuPG();
my $secret="123456";
sub gen_key_test {
    printf "%-40s", "Key generation";
    $gpg->gen_key(
        passphrase => "$secret",
                  name => "$username",
        email => "$email",
        comment=>"My GnuPG Key",
                 );

}

sub export_secret_test {
    printf "%-40s", "Exporting secret pub key";
    $gpg->export_keys(
            keys => "$username",
            secret => 0,
                       armor => 1,
                       output => "/home/$username/keyring.pub",
                     );
}
sub export_secret_test2 {
    printf "%-40s", "Exporting secret key";
    $gpg->export_keys(
            keys => "$username",
            secret => 1,
                       armor => 1,
                       output => "/home/$username/keyring.sec",
                     );
}
my @tests = qw(
  gen_key_test
 export_secret_test
 export_secret_test2
   );
if ( defined $ENV{TESTS} ) {
    @tests = split /\s+/, $ENV{TESTS};
}

print "1..", scalar @tests, "\n";
my $i = 1;
for ( @tests ) {
    eval {
        no strict 'refs'; # We are using symbolic references

        &$_();
    };
    if ( $@ ) {
        print "not ok $i: $@";
    } else {
        print "ok $i\n";
    }
    $i++;
}




阅读(617) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~