releasing/cbrtools/perl/Crypt.pm
author Ross Qin <ross.qin@nokia.com>
Thu, 18 Nov 2010 16:02:32 +0800
changeset 697 818fe0ed324b
parent 602 3145852acc89
permissions -rw-r--r--
Moving feature configuration out of the buildrom scope.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
# All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
# Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
# Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
# Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
package Crypt;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
# Constructor
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
sub New {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
  my $invocant = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
  my $class = ref($invocant) || $invocant;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
  my %args = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
  my $self = {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
	      defaultPath => $args{default_path},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
	      verbose => $args{verbose}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
	     };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
  bless $self, $class;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
  $self->Initialize();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
  return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
sub Initialize {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
  #convert defaultPath attribute to correct format
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
  if ($self->{defaultPath}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
    $self->DefaultPath($self->{defaultPath});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
# Public getters/setters
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
sub DefaultPath {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
  if (defined $_[0]) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
    my $defaultPath = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
    $defaultPath =~ s/\\/\//g;  #replace '\'s with / 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
    $defaultPath =~ s/\/+$//;   #remove trailing '/'s  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
    $self->{defaultPath} = $defaultPath;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
    delete $self->{publicKeys};   #new default path implies new keyring files so delete  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
    delete $self->{secretKeys};   #the current key lists
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
  return $self->{defaultPath};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
# Public methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
sub Encrypt {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
  my $plainText = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
  my $cipherText = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
  my @recipientKeys = @{$_[0]};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
  unless (defined $plainText and defined $cipherText and @recipientKeys) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
    die "Error: Incorrect arguments for encryption.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
  $plainText=~ s/\\/\//g;  #replace '\'s with /`s
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
  $cipherText=~ s/\\/\//g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
  if ($self->{verbose} > 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
    print "Encrypting $plainText with key(s) ".join(", ",@recipientKeys)."\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
  unless (-e $plainText) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
    die "Error: Encryption aborted. $plainText does not exist.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
  #check to see if all the recipient keys exist on the public keyring
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
  foreach my $recipientKey (@recipientKeys) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
    $self->PublicKeyExists($recipientKey) 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
      or die "Error: Encryption failed. $recipientKey not in keyring.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
  #call subclass method to actually encrypt file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
  $self->DoEncrypt($plainText, $cipherText, \@recipientKeys);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
  #throw an error if encrypted file not created
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
  unless (-e $cipherText) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
    die "Error: Encryption of $plainText failed.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
sub Decrypt {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
  my $cipherText = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
  my $plainText = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
  my $passPhrase = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
  unless (defined $plainText and defined $cipherText and defined $passPhrase) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
    die "Error: Incorrect arguments for decryption.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
  $plainText=~ s/\\/\//g;  #replace '\'s with /`s
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
  $cipherText=~ s/\\/\//g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
  if ($self->{verbose} > 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
    print "Decrypting $cipherText\n";    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
  unless (-e $cipherText) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
    die "Error: Decryption aborted. $cipherText does not exist.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
  #call subclass method to actually decrypt file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
  $self->DoDecrypt($cipherText, $plainText, $passPhrase);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
  #throw an error if decrypted file not created
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
  unless (-e $plainText) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
    die "Error: Decryption of $cipherText failed.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
  }	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
sub PublicKeyList {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
  unless (exists $self->{publicKeys}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
    #call subclass method to get key list
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
    foreach my $key (@{$self->GetPublicKeyList()}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
      $self->{publicKeys}->{uc($key)} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
    }	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
  my @keys = keys %{$self->{publicKeys}};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
  return \@keys;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
sub SecretKeyList {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
  unless (exists $self->{secretKeys}) { 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
    #call subclass method to get key list 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
    foreach my $key (@{$self->GetSecretKeyList()}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
      $self->{secretKeys}->{uc($key)} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
  my @keys = keys %{$self->{secretKeys}};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
  return \@keys;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
sub PublicKeyExists {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
  my $requiredKey = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
  unless (exists $self->{publicKeys}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
    $self->PublicKeyList();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
  return ($self->{publicKeys}->{uc($requiredKey)});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
sub SecretKeyExists {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
  my $requiredKey = $_[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
  unless (exists $self->{secretKeys}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
    $self->SecretKeyList();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
  return ($self->{secretKeys}->{uc($requiredKey)});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
# Abstract methods (must be implemented in a subclass)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
sub DoEncrypt {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
  die "Error: Call to abstract method ".ref($_[0])."::_DoEncrypt.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
sub DoDecrypt {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
  die "Error: Call to abstract method ".ref($_[0])."::_DoDecrypt.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
sub GetPublicKeyList {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
  die "Error: Call to abstract method ".ref($_[0])."::_GetPublicKeyList.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
sub GetSecretKeyList {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
  die "Error: Call to abstract method ".ref($_[0])."::_GetSecretKeyList.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
# Private methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
sub Quoted {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
  my $string = $_[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
  return ($string =~ /^\s*(\".*\")\s*$/) ? $1 : "\"$string\"";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
Crypt.pm - Abstract base class to crypt modules.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
 use Crypt::PGP;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
 $crypt = Crypt::PGP->New(default_path => 'somePath/someDir',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
                          verbose => 1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   221
 $crypt->DefaultPath('somedir/anotherdir');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   222
 $defaultpath = $crypt->DefaultPath();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   223
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
 @publickeys = @{$crypt->PublicKeyList()};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
 @secretkeys = @{$crypt->SecretKeyList()};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
 $crypt->Encrypt('somefile.txt', 'somefile.pgp', ['0x24534213', '0x1EA3B4DC', '0x8721DACE']);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
 $crypt->Decrypt('somefile.pgp', 'somefile.txt', 'mypassphrase');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
C<Crypt> is the abstract base class to a family of modules of the form C<Crypt::>F<PGPTool> which are simple wrappers over PGP command line tools. Each module in the C<Crypt> directory must implement the following abstract interface...
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   237
=item * DoEncrypt($plainText, $cipherText, \@recipientKeys)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   238
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   239
Should encrypt the C<$plainText> file with the public keys C<@recipientKeys> and store the result in the C<$cipherText> file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   241
=item * DoDecrypt($cipherText, $plainText, $passPhrase)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   242
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   243
Should decrypt the C<$cipherText> file using the secret key with pass phrase C<$passPhrase> and store the result in the C<$plainText> file. Must die with C<"BAD_PASSPHRASE"> if passphrase incorrect and C<"NO_SECKEY"> if secret key not available for decrypting file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
=item * array_ref GetPublicKeyList( )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
Should return the list of keyids stored on the public keyring.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
=item * array_ref GetSecretKeyList( )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   250
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   251
Should return the list of keyids stored on the secret keyring.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   252
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   253
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
B<NOTE:> A key id is an 8 digit hexadecimal number preceeded by a zero and an x (or X) e.g 0x12345678, 0X3eDC2A82
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
=head1 INTERFACE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
=head2 New
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   262
Passed an argument list in the form of hash key value pairs. The supported arguments are...
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   263
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   264
  default_path  => $path_string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
  verbose       => $verbosity_integer
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
Returns a reference to an object derived from C<Crypt> (C<Crypt> is abstract so cannot be instantiated)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   268
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   269
=head2 DefaultPath
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   270
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
Returns the current value of the C<defaultPath> attribute which stores the path to the users configuration and keyring files. If the C<defaultPath> is undefined then the tools default path is used. If passed a path as an argument sets the C<defaultPath> attribute to this value and updates the public and secret keyring file names. 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
=head2 Encrypt
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
Passed a plain text file name, a cipher text file name and a reference to an array of recipients pgp keyids. Encrypts the plain text file with the recipients keys. Outputs the result to the cipher text file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   276
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   277
=head2 Decrypt
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   278
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
Passed a cipher text file name, a plain text file name and the users private key pass phrase. Decrypts the cipher text file with the users private key and outputs the result to the plain text file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
=head2 PublicKeyList
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
Returns a reference to an array of keyids for keys stored in the public keyring
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
=head2 SecretKeyList
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
Returns a reference to an array of keyids for keys stored in the secret keyring
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
=head2 PublicKeyExists
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
Passed a public key id. Returns true if the key exists in the public keyring
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
=head2 SecretKeyExists
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
Passed a secret key id. Returns true if the key exists in the secret keyring
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
=head1 KNOWN BUGS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
None
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
 Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
 All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
 This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
 under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
 which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
 at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
 Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
 Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
 Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
 Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
=cut