Showing posts with label RSA. Show all posts
Showing posts with label RSA. Show all posts
Thursday, October 3, 2019
JAVA RSA Sign Data and Verify
Simple Note
Add Sign data by Signature with Private Key and verify data by Signature with Public Key
RSAUtils.java
Also add Test Cases and Performance Testing
TestRSAUtils.java
TestRSAPerformance.java
and update the Performance Testing google sheet
JAVA RSA Performance Testing
Reference
Java Cryptography Architecture (JCA) Reference Guide
Generating and Verifying a Signature Using Generated Keys
https://docs.oracle.com/javase/8/docs/technotes/guides/security/crypto/CryptoSpec.html#SigEx
Java Doc of Signature
https://docs.oracle.com/javase/7/docs/api/java/security/Signature.html
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
Labels:
Crypto,
Decryption,
Encryption,
Java,
Performance,
RSA
Subscribe to:
Posts (Atom)