http://www.perlmonks.org?node_id=877274

andreas1234567 has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking for deterministic asymmetric encryption (The "database search" example given in the wikipedia article is very closely related to mine):
A deterministic encryption scheme (as opposed to a probabilistic encryption scheme) is a cryptosystem which always produces the same ciphertext for a given plaintext and key, even over separate executions of the encryption algorithm. Examples of deterministic encryption algorithms include the RSA cryptosystem (without encryption padding)
The documentation for Crypt::RSA specifically says:
[..] there exists a scheme called Simple RSA[16] that provides security without padding. However, Crypt::RSA doesn't implement this scheme yet.
Is there a CPAN module that implements deterministic asymmetric encryption?
$ perl -l use strict; use warnings; use Log::Log4perl; use Crypt::RSA; my $rsa = new Crypt::RSA; my ($public, $private) = $rsa->keygen( Identity => 'Lord Macbeth <macbeth@glamis.com>', Size => 1024, Password => 'A day so foul & fair', Verbosity => 0, ) or die $rsa->errstr(); my $secret = q{Thanks for all the fish}; my $ciphertext1 = $rsa->encrypt(Message => $secret, Key => $public, Armour => 1,) || die $rsa->errstr(); my $ciphertext2 = $rsa->encrypt(Message => $secret, Key => $public, Armour => 1,) || die $rsa->errstr(); $ciphertext1 eq $ciphertext2 ? print q{deterministic} : print q{not de +terministic}; __END__ not deterministic $
Update: What would the consequences be if I disregarded the advise in the documentation:
In any event, Crypt::RSA::Primitives (without padding) should never be used directly.
my $prim = new Crypt::RSA::Primitives; my $ctxt1 = $prim->core_encrypt (Key => $public, Plaintext => $pan); my $ctxt2 = $prim->core_encrypt (Key => $public, Plaintext => $pan); $ctxt1 eq $ctxt2 ? print q{deterministic} : print q{not deterministic} +;
Prints "deterministic".
--
No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]