Captcha-Stateless-Text
view release on metacpan or search on metacpan
author:
- Lester Hightower <hightowe@cpan.org>
license: perl
distribution_type: module
requires:
# Perl >= v5.20 needed for feature "signatures"
perl: '5.020000'
Sub::Util: 0
Lingua::EN::Nums2Words: 0
Try::Tiny: 0
Crypt::Mode::CBC: 0
JSON: 0
recommends:
build_requires:
urls:
license: http://dev.perl.org/licenses/
meta-spec:
version: 1.3
url: http://module-build.sourceforge.net/META-spec-v1.3.html
generated_by: Module::Build version 0.20
Makefile.PL view on Meta::CPAN
DISTNAME => 'Captcha-Stateless-Text',
VERSION_FROM => 'lib/Captcha/Stateless/Text.pm',
LICENSE => 'artistic_2',
AUTHOR => 'Lester Hightower <hightowe@cpan.org>',
dist => {'COMPRESS'=>'zip', 'SUFFIX' => '.zip'},
MIN_PERL_VERSION => 'v5.20', # for feature "signatures"
PREREQ_PM => {
'Sub::Util' => 0,
'Lingua::EN::Nums2Words' => 0,
'Try::Tiny' => 0,
'Crypt::Mode::CBC' => 0,
'JSON' => 0,
},
);
print "\n";
print "Do a 'make test' to test the module before installation\n";
print "Do a 'make install' to install the module.\n";
lib/Captcha/Stateless/Text.pm view on Meta::CPAN
use strict;
use v5.20; # Version needed for feature signatures
use feature qw(signatures);
no warnings qw(experimental::signatures);
use Sub::Util qw(set_subname); # core
use MIME::Base64 qw(); # core
use Digest::MD5 qw(md5_hex); # core
use Data::Dumper; # core
use Try::Tiny; # libtry-tiny-perl
use Crypt::Mode::CBC; # libcryptx-perl
use JSON qw(to_json from_json); # libjson-perl
use Lingua::EN::Nums2Words; # From CPAN (cpanm Lingua::EN::Nums2Words)
$Data::Dumper::Sortkeys = 1;
Lingua::EN::Nums2Words::set_case('lower');
our $VERSION = "0.5";
sub Version { $VERSION; }
my %QAfuncs = {}; # Holds our private __ANON__ subroutines
lib/Captcha/Stateless/Text.pm view on Meta::CPAN
return MIME::Base64::encode_base64url($d, ''); # '' for no line breaks
}
sub decrypt_b64($self, $data) {
my $d = MIME::Base64::decode_base64url($data);
return my_crypt_cbc($self, 'decrypt', $self->{cipher}, $self->{key}, $self->{iv}, $d);
}
# Helper function to centralize and reduce code duplication
sub my_crypt_cbc($self, $mode, $cipher, $key, $iv, $data) {
my $pkg = __PACKAGE__;
my $cbc = Crypt::Mode::CBC->new($cipher, 1);
if ($mode eq 'encrypt') {
my $payload = undef;
try {
$payload = $cbc->encrypt($data, $key, $iv); # ENCRYPT
} catch {
warn("$pkg my_crypt_cbc() failed to $mode with error: $_");
$payload = undef;
};
return $payload;
} elsif ($mode eq 'decrypt') {
use warnings;
use Test::More 'no_plan';
use lib './lib';
# The modules that we require
my @req_mods = qw(
Captcha::Stateless::Text
Lingua::EN::Nums2Words
Try::Tiny
Crypt::Mode::CBC
JSON
);
foreach my $mod (@req_mods) {
use_ok $mod;
}
my $captcha = Captcha::Stateless::Text->new();
$captcha->set_iv('gkbx5g9hsvhqrosg'); # Must be 16 bytes / 128 bits
$captcha->set_key('tyDjb39dQ20pdva0lTpyuiowWfxSSwa9'); # 32 bytes / 256 bits (AES256)
my $ep_pre = $captcha->get_ep_pre();
( run in 0.690 second using v1.01-cache-2.11-cpan-e1769b4cff6 )