=pod =head1 NAME Crypt::MagicSignatures::Key - MagicKeys for the Salmon Protocol =head1 SYNOPSIS use Crypt::MagicSignatures::Key; my $mkey = Crypt::MagicSignatures::Key->new('RSA.mVgY...'); my $sig = $mkey->sign('This is a message'); if ($mkey->verify('This is a message', $sig)) { print 'The signature is valid for ' . $mkey->to_string; }; =head1 DESCRIPTION L implements MagicKeys as described in the L to sign messages of the L. MagicSignatures is a "robust mechanism for digitally signing nearly arbitrary messages". See L for using MagicKeys to sign MagicEnvelopes. =head1 ATTRIBUTES =head2 n print $mkey->n; $mkey->n('456789...'); The MagicKey modulus. =head2 e print $mkey->e; $mkey->e(3); The MagicKey public exponent. Defaults to 65537. =head2 d print $mkey->d; $mkey->d('234567...'); The MagicKey private exponent. =head2 size print $mkey->size; The MagicKey keysize in bits. =head1 METHODS =head2 new my $mkey = Crypt::MagicSignatures::Key->new(<<'MKEY'); RSA. mVgY8RN6URBTstndvmUUPb4UZTdwvw mddSKE5z_jvKUEK6yk1u3rrC9yN8k6 FilGj9K0eeUPe2hf4Pj-5CmHww==. AQAB. Lgy_yL3hsLBngkFdDw1Jy9TmSRMiH6 yihYetQ8jy-jZXdsZXd8V5ub3kuBHH k4M39i3TduIkcrjcsiWQb77D8Q== MKEY $mkey = Crypt::MagicSignatures::Key->new( n => '13145688881420345...', d => '87637925876135637...', e => 3 ); The Constructor accepts MagicKeys in L or by attributes. =head2 generate my $mkey = Crypt::MagicSignatures::Key->new(size => 1024); Generate a new key. Requires L to be installed. Accepts the attributes C and C. In case no C attribute is given, the default key size for generation is 512 bits, which is also the minimum size. The maximum size is 4096 bits. =head2 sign my $sig = $mkey->sign('This is a message'); Signs a message and returns the signature. The key needs to be a private key. The signature algorithm is based on L. =head2 verify my $sig = $priv_key->sign('This is a message'); # Successfully verify signature if ($pub_key->verify('This is a message', $sig)) { print 'The signature is okay.'; } # Fail to verify signature else { print 'The signature is wrong!'; }; Verifies a signature of a message based on the public component of the key. Returns a C value on success and C otherwise. =head2 to_string my $pub_key = $mkey->to_string; my $priv_key = $mkey->to_string(1); Returns the public key as a string in L. If a C value is passed to the method, the full key (including the private exponent if existing) is returned. =head1 FUNCTIONS =head2 b64url_encode use Crypt::MagicSignatures::Key qw/b64url_encode/; print b64url_encode('This is a message'); print b64url_encode('This is a message', 0); Encodes a string as base-64 with URL safe characters. A second parameter indicates, if trailing equal signs are wanted. The default is C. This differs from L. The function can be exported. =head2 b64url_decode use Crypt::MagicSignatures::Key qw/b64url_decode/; print b64url_decode('VGhpcyBpcyBhIG1lc3NhZ2U='); Decodes a base-64 string with URL safe characters. Characters not part of the character set are silently ignored. The function can be exported. =head1 DEPENDENCIES For signing and verification there are no dependencies other than Perl v5.10.1 and core modules. For key generation L v0.21 is necessary. Either L (preferred) or L is strongly recommended for speed improvement (signing and verification) as well as L and L (key generation). =head1 KNOWN BUGS AND LIMITATIONS The signing and verification is not guaranteed to be compatible with other implementations! =head1 SEE ALSO L, L, L, L. =head1 AVAILABILITY https://github.com/Akron/Crypt-MagicSignatures-Key =head1 COPYRIGHT AND LICENSE Copyright (C) 2012-2016, L. This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. =cut