require XSLoader;
XSLoader::load('CryptX', $VERSION);
use Carp;
my $has_json;
BEGIN {
$has_json = 1 if eval { require JSON; 1 };
}
sub _croak {
die @_ if ref $_[0] || !$_[-1];
if ($_[-1] =~
de_json {
croak "FATAL: cannot find JSON module" if !$has_json;
return JSON->new->utf8->decode(shift);
}
sub _encode_json {
croak "FATAL: cannot find JSON module" if !$has_json;
return JSON->
qi => encode_b64u(pack("H*", $kh->{qP})),
};
return $wanthash ? $hash : CryptX::_encode_json($hash);
}
elsif ($type eq 'public') {
return unless $kh->{N} && $kh->{e};
for (qw/N e
e => encode_b64u(pack("H*", $kh->{e})),
};
return $wanthash ? $hash : CryptX::_encode_json($hash);
}
}
sub export_key_jwk_thumbprint {
my ($self, $hash_name) = @_;
local $SIG{__DIE_
$self->export_key_jwk('public', 1);
my $json = CryptX::_encode_json({kty=>$h->{kty}, n=>$h->{n}, e=>$h->{e}});
return digest_data_b64u($hash_name, $json);
}
sub import_key {
my ($self, $key, $
f->_import_openssh($data, undef);
}
elsif ($data =~ /^\s*(\{.*?\})\s*$/s) { # JSON
my $h = CryptX::_decode_json("$1");
if ($h->{kty} && $h->{kty} eq "OKP" && $h->{crv} && $h->{crv} eq 'Ed2
iv})) if $type && $type eq 'private' && $kh->{priv};
return $wanthash ? $hash : CryptX::_encode_json($hash);
}
sub CLONE_SKIP { 1 } # prevent cloning
1;
=pod
=head1 NAME
Crypt::PK::Ed25519 - Di
EFB6B92D99CD457E2137172C0D749FE2B5A0C142DAD",
});
# or a hash with items corresponding to JWK (JSON Web Key)
$pk->import_key({
kty => "OKP",
crv => "Ed25519",
d => "RcEJum_S
d => encode_b64u(pack("H*", $kh->{k})),
};
return $wanthash ? $hash : CryptX::_encode_json($hash);
}
elsif ($type && $type eq 'public') {
return unless $kh->{pub_x} && $kh->{pub_y}
y => encode_b64u(pack("H*", $kh->{pub_y})),
};
return $wanthash ? $hash : CryptX::_encode_json($hash);
}
}
sub export_key_jwk_thumbprint {
my ($self, $hash_name) = @_;
local $SIG{__DIE_
export_key_jwk('public', 1);
my $json = CryptX::_encode_json({crv=>$h->{crv}, kty=>$h->{kty}, x=>$h->{x}, y=>$h->{y}});
return digest_data_b64u($hash_name, $json);
}
sub import_key {
my ($self,
f->_import_pem($data, $password);
}
elsif ($data =~ /^\s*(\{.*?\})\s*$/s) { # JSON
my $h = CryptX::_decode_json("$1") || {};
if ($h->{kty} && $h->{kty} eq "OKP" && $h->{crv} && $h->{crv} e
iv})) if $type && $type eq 'private' && $kh->{priv};
return $wanthash ? $hash : CryptX::_encode_json($hash);
}
sub CLONE_SKIP { 1 } # prevent cloning
1;
=pod
=head1 NAME
Crypt::PK::X25519 - Asy
9527721DABA3261C0BB1BEFDE7B4BBDAC631D454651",
});
# or a hash with items corresponding to JWK (JSON Web Key)
$pk->import_key({
kty => "OKP",
crv => "X25519",
d => "AC-T0Qulc