Crypt-GCrypt
view release on metacpan or search on metacpan
(thanks to Paul Kolano for bug report and test case)
version 1.17 (2007/10/29):
- removed warnings on platforms with signed chars
(untested)
version 1.16 (2006/12/20):
- fixed compilation issue with GCC 2.95
- test compatibility with Crypt::CBC 2.17
- minor code cleanup
version 1.15 (2006/01/06):
- fixed t/05-size.t (now skips if we don't have Devel::Size)
version 1.14 (2006/01/06):
- fixed compilation on Solaris (thanks to Andre Schmidt for bug report)
- fixed minor memory leaks
- minor bug fixes
- fixed typo in POD
- improved Makefile.PL for locating libgcrypt
- added t/03-pod.t and t/04-podcoverage.t
version 1.1 (2005/10/10):
- added finish() to handle partial blocks
- added padding with null and standard methods
- added compatibility test with Crypt::CBC
version 1.00 (2005/10/09):
- new
if (have_mode) {
switch (mode_s[0]) {
case 'e':
if (strcmp(mode_s+1, "cb") == 0)
RETVAL->mode = GCRY_CIPHER_MODE_ECB;
break;
case 'c':
if (strcmp(mode_s+1, "fb") == 0)
RETVAL->mode = GCRY_CIPHER_MODE_CFB;
else if (strcmp(mode_s+1, "bc") == 0)
RETVAL->mode = GCRY_CIPHER_MODE_CBC;
break;
case 's':
if (strcmp(mode_s+1, "tream") == 0)
RETVAL->mode = GCRY_CIPHER_MODE_STREAM;
break;
case 'o':
if (strcmp(mode_s+1, "fb") == 0)
RETVAL->mode = GCRY_CIPHER_MODE_OFB;
break;
}
} else {
RETVAL->mode = RETVAL->blklen > 1 ? GCRY_CIPHER_MODE_CBC
: GCRY_CIPHER_MODE_STREAM;
}
if (!RETVAL->mode)
croak("Unknown mode %s", mode_s);
/* Init cipher */
RETVAL->err = gcry_cipher_open(&RETVAL->h, algo, RETVAL->mode, c_flags);
if (RETVAL->h == NULL) XSRETURN_UNDEF;
}
if (RETVAL->type == CG_TYPE_DIGEST) {
lib/Crypt/GCrypt.pm view on Meta::CPAN
When the last block of plaintext is shorter than the block size, it must be
padded before encryption. Padding should permit a safe unpadding after
decryption. Crypt::GCrypt currently supports two methods:
=over 8
=item B<standard>
This is also known as PKCS#5 padding, as it's binary safe. The string is padded
with the number of bytes that should be truncated. It's compatible with Crypt::CBC.
=item B<null>
Only for text strings. The block will be padded with null bytes (00). If the last
block is a full block and blocksize is 8, a block of "0000000000000000" will be
appended.
=item B<none>
By setting the padding method to "none", Crypt::GCrypt will only accept a multiple
lib/Crypt/GCrypt.pm view on Meta::CPAN
corresponding ciphertext. The output is buffered; this means that
you'll only get multiples of $cipher's block size and that at the
end you'll have to call L</"finish()">.
=head2 finish()
$ciphertext .= $cipher->finish;
$plaintext .= $cipher->finish;
The CBC algorithm must buffer data blocks internally until there are even
multiples of the encryption algorithm's blocksize (typically 8 or 16 bytes).
After the last call to encrypt() or decrypt() you should call finish() to flush
the internal buffer and return any leftover data. This method will also take care
of padding/unpadding of data (see the L</padding> option above).
=head2 decrypt()
$plaintext = $cipher->decrypt($ciphertext);
The counterpart to encrypt, decrypt takes a I<$ciphertext> and produces the
t/02-compatibility.t view on Meta::CPAN
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 01-use.t'
#########################
use Test;
BEGIN {
plan tests => 1; # <--- number of tests
$HAVE_CRYPT_CBC = eval "use Crypt::CBC (); 1;";
$HAVE_CAST5 = eval "use Crypt::CAST5 (); 1;";
};
use ExtUtils::testlib;
use Crypt::GCrypt;
#########################
skip(!($HAVE_CRYPT_CBC && $HAVE_CAST5), sub {
my $c = Crypt::GCrypt->new(
type => 'cipher',
algorithm => 'cast5',
mode => 'cbc',
padding => 'standard'
);
$c->start('encrypting');
$c->setkey(my $key = "the key, the key");
$c->setiv("12345678");
my $p = 'plain text';
my $e = $c->encrypt($p);
$e .= $c->finish;
my $cipher = Crypt::CBC->new(
-key => $key,
-literal_key => 1,
-cipher => 'CAST5',
-padding => 'standard',
-iv => "12345678",
-header => "none"
);
$cipher->start('decrypting');
my $d = $cipher->crypt($e);
$d .= $cipher->finish;
( run in 1.631 second using v1.01-cache-2.11-cpan-e1769b4cff6 )