Crypt::DES - Perl DES encryption module


Crypt-DES documentation Contained in the Crypt-DES distribution.

Index


Code Index:

NAME

Top

Crypt::DES - Perl DES encryption module

SYNOPSIS

Top

    use Crypt::DES;




DESCRIPTION

Top

The module implements the Crypt::CBC interface, which has the following methods

blocksize =item keysize =item encrypt =item decrypt

FUNCTIONS

Top

blocksize

Returns the size (in bytes) of the block cipher.

keysize

Returns the size (in bytes) of the key. Optimal size is 8 bytes.

new
	my $cipher = new Crypt::DES $key;

This creates a new Crypt::DES BlockCipher object, using $key, where $key is a key of keysize() bytes.

encrypt
	my $cipher = new Crypt::DES $key;
	my $ciphertext = $cipher->encrypt($plaintext);

This function encrypts $plaintext and returns the $ciphertext where $plaintext and $ciphertext should be of blocksize() bytes.

decrypt
	my $cipher = new Crypt::DES $key;
	my $plaintext = $cipher->decrypt($ciphertext);

This function decrypts $ciphertext and returns the $plaintext where $plaintext and $ciphertext should be of blocksize() bytes.

EXAMPLE

Top

	my $key = pack("H16", "0123456789ABCDEF");
	my $cipher = new Crypt::DES $key;
	my $ciphertext = $cipher->encrypt("plaintex");	# NB - 8 bytes
	print unpack("H16", $ciphertext), "\n";

NOTES

Top

Do note that DES only uses 8 byte keys and only works on 8 byte data blocks. If you're intending to encrypt larger blocks or entire files, please use Crypt::CBC in conjunction with this module. See the Crypt::CBC documentation for proper syntax and use.

Also note that the DES algorithm is, by today's standard, weak encryption. Crypt::Blowfish is highly recommended if you're interested in using strong encryption and a faster algorithm.

SEE ALSO

Top

Crypt::Blowfish Crypt::IDEA

Bruce Schneier, Applied Cryptography, 1995, Second Edition, published by John Wiley & Sons, Inc.

COPYRIGHT

Top

MAINTAINER

Top

This single-algorithm package and cross-platform code is maintained by Dave Paris <amused@pobox.com>.


Crypt-DES documentation Contained in the Crypt-DES distribution.

#
# Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/)
# All rights reserved.
#
# Modifications are Copyright (c) 2000, W3Works, LLC
# All Rights Reserved.

package Crypt::DES;

require Exporter;
require DynaLoader;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);

@ISA = qw(Exporter DynaLoader);

# Items to export into callers namespace by default
@EXPORT =	qw();

# Other items we are prepared to export if requested
@EXPORT_OK =	qw();

$VERSION = '2.05';
bootstrap Crypt::DES $VERSION;

use strict;
use Carp;

sub usage
{
	my ($package, $filename, $line, $subr) = caller(1);
	$Carp::CarpLevel = 2;
	croak "Usage: $subr(@_)";
}


sub blocksize { 8; }
sub keysize   { 8; }

sub new
{
	usage("new DES key") unless @_ == 2;

	my $type = shift;
	my $self = {};
	bless $self, $type;

	$self->{'ks'} = Crypt::DES::expand_key(shift);

	return $self;
}

sub encrypt
{
	usage("encrypt data[8 bytes]") unless @_ == 2;

	my ($self,$data) = @_;
	return Crypt::DES::crypt($data, $data, $self->{'ks'}, 1);
}

sub decrypt
{
	usage("decrypt data[8 bytes]") unless @_ == 2;

	my ($self,$data) = @_;
	return Crypt::DES::crypt($data, $data, $self->{'ks'}, 0);
}

1;

__END__