Crypt-Fernet
view release on metacpan or search on metacpan
0.0302 Fri Nov 29 17:39:00 2024
- update version
0.0301 Wed Sep 11 17:22:00 2024 Iain Campbell <cpanic@cpan.org>
- Add Crypt::Rijndael to [Prereqs/TestPrereqs] as it wasn't
picked up by Dist::Zilla automatically and its absence
causes build builures on CPANTs.
0.03 Wed Sep 11 17:22:00 2024 Iain Campbell <cpanic@cpan.org>
- update lib/Crypt/Fernet.pm
do not pass "blocksize" to &Crypt::CBC::new because:
(a) it is not an option recognised by Crypt::CBC, and it
complains, resulting in failure to test and install.
(b) Crypt::CBC is able to determine the blocksize, which
is confirmed to be 16 for this cipher.
- Added a Dist::Zilla dist.ini file so that a distribution
can be generated containing machine-readable dependency
declaration.
0.02 Web Aug 20 01:33:59 2014
- update LICENSE
- update test cases
- update dependencies
- update readme
---
abstract: 'Perl extension for Fernet (symmetric encryption)'
author:
- 'Wan Leung Wong <me@wanleung.com>'
build_requires:
Crypt::CBC: '0'
Crypt::Rijndael: '0'
Crypt::URandom: '0'
Digest::SHA: '0'
MIME::Base64::URLSafe: '0'
Test::More: '0'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.030, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: Crypt-Fernet
requires:
Crypt::CBC: '0'
Crypt::Rijndael: '0'
Crypt::URandom: '0'
Digest::SHA: '0'
Exporter: '5.57'
MIME::Base64::URLSafe: '0'
bytes: '0'
perl: '5.018002'
strict: '0'
warnings: '0'
version: '0.0306'
Makefile.PL view on Meta::CPAN
"ABSTRACT" => "Perl extension for Fernet (symmetric encryption)",
"AUTHOR" => "Wan Leung Wong <me\@wanleung.com>",
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => 0
},
"DISTNAME" => "Crypt-Fernet",
"LICENSE" => "perl",
"MIN_PERL_VERSION" => "5.018002",
"NAME" => "Crypt::Fernet",
"PREREQ_PM" => {
"Crypt::CBC" => 0,
"Crypt::Rijndael" => 0,
"Crypt::URandom" => 0,
"Digest::SHA" => 0,
"Exporter" => "5.57",
"MIME::Base64::URLSafe" => 0,
"bytes" => 0,
"strict" => 0,
"warnings" => 0
},
"TEST_REQUIRES" => {
"Crypt::CBC" => 0,
"Crypt::Rijndael" => 0,
"Crypt::URandom" => 0,
"Digest::SHA" => 0,
"MIME::Base64::URLSafe" => 0,
"Test::More" => 0
},
"VERSION" => "0.0306",
"test" => {
"TESTS" => "t/*.t"
}
);
my %FallbackPrereqs = (
"Crypt::CBC" => 0,
"Crypt::Rijndael" => 0,
"Crypt::URandom" => 0,
"Digest::SHA" => 0,
"Exporter" => "5.57",
"MIME::Base64::URLSafe" => 0,
"Test::More" => 0,
"bytes" => 0,
"strict" => 0,
"warnings" => 0
);
More Detail on the Fernet Spec:
https://github.com/fernet/spec/blob/master/Spec.md
Source of this project:
https://github.com/wanleung/Crypt-Fernet
# DEPENDENCIES
This module requires these other modules and libraries:
use Crypt::CBC;
use Digest::SHA qw(hmac_sha256);
use MIME::Base64::URLSafe;
# AUTHOR
Wan Leung Wong, <me@wanleung.com>
# COPYRIGHT AND LICENSE
The MIT License (MIT)
[MetaYAML]
[Manifest]
[MakeMaker]
[PruneCruft]
[AutoPrereqs]
[TestRelease]
[NextRelease]
[ConfirmRelease]
[UploadToCPAN]
[Prereqs / TestRequires]
Crypt::CBC = 0
Crypt::Rijndael = 0
Crypt::URandom = 0
Digest::SHA = 0
MIME::Base64::URLSafe = 0
lib/Crypt/Fernet.pm view on Meta::CPAN
# Preloaded methods go here.
sub fernet_genkey { Crypt::Fernet::generate_key() }
sub fernet_encrypt { Crypt::Fernet::encrypt(@_) }
sub fernet_verify { Crypt::Fernet::verify(@_) }
sub fernet_decrypt { Crypt::Fernet::decrypt(@_) }
use Crypt::CBC;
use Crypt::Rijndael;
use Crypt::URandom qw( urandom );
use Digest::SHA qw(hmac_sha256);
use MIME::Base64::URLSafe;
sub generate_key {
return _urlsafe_pading_base64_encode(urandom(32));
}
sub encrypt {
my ($key, $data) = @_;
my $b64decode_key = urlsafe_b64decode($key);
my $signkey = substr $b64decode_key, 0, 16;
my $encryptkey = substr $b64decode_key, 16, 16;
my $iv = urandom(16);
my $cipher = Crypt::CBC->new(-literal_key => 1,
-key => $encryptkey,
-iv => $iv,
-keysize => 16,
-padding => 'standard',
-cipher => 'Rijndael',
-header => 'none',
);
my $ciphertext = $cipher->encrypt($data);
my $pre_token = $FERNET_TOKEN_VERSION . _timestamp() . $iv . $ciphertext;
my $digest=hmac_sha256($pre_token, $signkey);
lib/Crypt/Fernet.pm view on Meta::CPAN
verify($key, $token, $ttl) or return;
my $b64decode_key = urlsafe_b64decode($key);
my $token_data = urlsafe_b64decode($token);
my $encryptkey = substr $b64decode_key, 16, 16;
my $iv = substr $token_data, 9, 16;
my $ciphertextlen = (length $token_data) - 25 - 32;
my $ciphertext = substr $token_data, 25, $ciphertextlen;
my $cipher = Crypt::CBC->new(-literal_key => 1,
-key => $encryptkey,
-iv => $iv,
-keysize => 16,
-padding => 'standard',
-cipher => 'Rijndael',
-header => 'none',
);
my $plaintext = $cipher->decrypt($ciphertext);
return $plaintext;
}
lib/Crypt/Fernet.pm view on Meta::CPAN
More Detail on the Fernet Spec:
https://github.com/fernet/spec/blob/master/Spec.md
Source of this project:
https://github.com/wanleung/Crypt-Fernet
=head1 DEPENDENCIES
This module requires these other modules and libraries:
use Crypt::CBC;
use Digest::SHA qw(hmac_sha256);
use MIME::Base64::URLSafe;
=head1 AUTHOR
Wan Leung Wong, E<lt>me@wanleung.comE<gt>
=head1 COPYRIGHT AND LICENSE
The MIT License (MIT)
t/Crypt-Fernet.t view on Meta::CPAN
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use strict;
use warnings;
use Test::More tests => 14;
BEGIN {
use_ok('Crypt::CBC');
use_ok('Digest::SHA');
use_ok('MIME::Base64::URLSafe');
use_ok('Crypt::Fernet')
};
my $key = Crypt::Fernet::generate_key();
my $plaintext = 'This is a test';
my $token = Crypt::Fernet::encrypt($key, $plaintext);
my $verify = Crypt::Fernet::verify($key, $token);
my $decrypttext = Crypt::Fernet::decrypt($key, $token);
( run in 0.677 second using v1.01-cache-2.11-cpan-e1769b4cff6 )