If you use PKCS # 1 1.5 or 2.0 RSA encryption ( view standards ), you will also encrypt a random add-on. This means that during transit PIN cannot be compared if the filling is kept secret and really random (this is not a salt that should be made public).
As for the database, it would be nice to get it out of normal operations as much as possible. Create a simple service that simply checks the PIN code after decryption, make sure that it does not have a buffer overflow, etc., And, if possible, use a different computer and access rights than the production server. Actually check this part, since the interface is small, it should not be difficult.
If you and the phones are ready for this, you can try ECC, but this is not for the meek. RSA encryption usually uses a small public metric (0x010001 recommended), so itβs faster than ECC for the phone. On the server (and during key creation), ECC is much faster. I would not recommend symmetric cryptography (AES / 3DES) for this.
Oh, and include the encryption public key in the application (for implicit trust), do not send it from the server. Keep the secret key secret and unavailable for anything other than the service already mentioned.
source share