home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / DES.pm < prev    next >
Encoding:
Perl POD Document  |  2001-05-02  |  1.3 KB  |  65 lines

  1. # $Id: DES.pm,v 1.7 2001/05/02 21:59:33 btrott Exp $
  2.  
  3. package Net::SSH::Perl::Cipher::DES;
  4.  
  5. use strict;
  6.  
  7. use Net::SSH::Perl::Cipher;
  8. use base qw( Net::SSH::Perl::Cipher );
  9.  
  10. use Net::SSH::Perl::Cipher::CBC;
  11. use Crypt::DES;
  12.  
  13. sub new {
  14.     my $class = shift;
  15.     my $ciph = bless { }, $class;
  16.     $ciph->init(@_) if @_;
  17.     $ciph;
  18. }
  19.  
  20. sub init {
  21.     my $ciph = shift;
  22.     my($key, $iv) = @_;
  23.     my $des = Crypt::DES->new(substr $key, 0, 8);
  24.     $ciph->{cbc} = Net::SSH::Perl::Cipher::CBC->new($des, $iv);
  25. }
  26.  
  27. sub encrypt {
  28.     my($ciph, $text) = @_;
  29.     $ciph->{cbc}->encrypt($text);
  30. }
  31.  
  32. sub decrypt {
  33.     my($ciph, $text) = @_;
  34.     $ciph->{cbc}->decrypt($text);
  35. }
  36.  
  37. 1;
  38. __END__
  39.  
  40. =head1 NAME
  41.  
  42. Net::SSH::Perl::Cipher::DES - Wrapper for SSH DES support
  43.  
  44. =head1 SYNOPSIS
  45.  
  46.     use Net::SSH::Perl::Cipher;
  47.     my $cipher = Net::SSH::Perl::Cipher->new('DES', $key);
  48.     print $cipher->encrypt($plaintext);
  49.  
  50. =head1 DESCRIPTION
  51.  
  52. I<Net::SSH::Perl::Cipher::DES> provides DES encryption
  53. support for I<Net::SSH::Perl>. To do so it wraps around
  54. I<Crypt::DES>, a C/XS implementation of the DES algorithm.
  55.  
  56. The DES algorithm used here is in CBC filter mode with a
  57. key length of 8 bytes.
  58.  
  59. =head1 AUTHOR & COPYRIGHTS
  60.  
  61. Please see the Net::SSH::Perl manpage for author, copyright,
  62. and license information.
  63.  
  64. =cut
  65.