Sunday, September 29, 2019

JAVA RSA Generate KeyPair, Encryption, Decryption and Performance Testing


Motivation

To try RSA Enc/Dec and check its performance.

Simple Note

Test file TestRSAUtils.java

Implementation RSAUtils.java

Performance testing TestRSAPerformance.java

Refactoring

Move AESUtils.encrypt and AESUtils.decrypt to CryptoUtils since they are no different from RSA encrypt/decrypt.

Still wrap them in AESUtils/RSAUtils for convenience.
(Can import less class) (Just one class less)

Hmm...


Performance Testing

Test over
PublicKey/PrivateKey, Encryption/Decryption,
Create Cipher each time/Reuse Cipher,
Key Size 1024/2048/4096/8192 bits
total 32 cases, 100 runs each

Results listed in the google sheet
JAVA RSA Performance Testing

Not very accurate but...

Summary

1. PublicKey Enc/Dec is faster than PrivateKey Enc/Dec

2. Key Size affects, the longer the slower.

3. Reuse Cipher similar to create Cipher each time, sometimes even slower.

Conclusions

1. Use proper Key Size, 2048 probably a good choice.

2. Can create Cipher each time, no need to cache it.

3. Can also cache and reuse Cipher, will slightly increase performance in most cases.

References

Java: How can I generate PrivateKey from a string?

Load RSA public key from file

No comments:

Post a Comment