package CryptX; use strict; use warnings ; our $VERSION = '0.048'; use base qw(Exporter); our @EXPORT_OK = qw( _decode_json _encode_json); require XSLoader; XSLoader::load('CryptX', $VERSION); use Carp; my $has_json; BEGIN { if (eval { require Cpanel::JSON::XS }) { Cpanel::JSON::XS->import(qw(encode_json decode_json)); $has_json = 1; } elsif (eval { require JSON::XS }) { JSON::XS->import(qw(encode_json decode_json)); $has_json = 2; } elsif (eval { require JSON::PP }) { JSON::PP->import(qw(encode_json decode_json)); $has_json = 3; } else { $has_json = 0; } } sub _decode_json { croak "FATAL: cannot find JSON::PP or JSON::XS or Cpanel::JSON::XS" if !$has_json; decode_json(shift); } sub _encode_json { croak "FATAL: cannot find JSON::PP or JSON::XS or Cpanel::JSON::XS" if !$has_json; my $data = shift; my $rv = encode_json($data); # non-canonical fallback return(eval { Cpanel::JSON::XS->new->canonical->encode($data) } || $rv) if $has_json == 1; return(eval { JSON::XS->new->canonical->encode($data) } || $rv) if $has_json == 2; return(eval { JSON::PP->new->canonical->encode($data) } || $rv) if $has_json == 3; return($rv); } 1; __END__ =head1 NAME CryptX - Crypto toolkit (self-contained no external libraries needed) =head1 DESCRIPTION Cryptography in CryptX is based on L Currently available modules: =over =item * Ciphers - see L and related modules L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L =item * Block cipher modes L, L, L, L, L =item * Stream ciphers L, L, L =item * Authenticated encryption modes L, L, L, L, L =item * Hash Functions - see L and related modules L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L =item * Message Authentication Codes L, L, L, L, L, L, L =item * Public key cryptography L, L, L, L =item * Cryptographically secure random number generators L, L, L, L, L, L =item * Key derivation functions - PBKDF1, PBKFD2 and HKDF L =back =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 COPYRIGHT Copyright (c) 2013+ DCIT, a.s. L / Karel Miko