| | |
Java Encryption: RSA Block Size?
![]() |
•
•
Join Date: Apr 2008
Posts: 49
Reputation:
Solved Threads: 3
0
#11 Oct 18th, 2009
Unfortunately "NoPadding" is another pesky requirement for this assignment. I wish I didn't have to.
•
•
Join Date: Apr 2008
Posts: 49
Reputation:
Solved Threads: 3
0
#12 Oct 18th, 2009
I only compared the original text to the decrypted text at a glance, but it appeared to have worked. Below is my entire encryption/decryption process with RSA. Like I said, it appears to have worked great. Does it make sense to you?
java Syntax (Toggle Plain Text)
KeyPairGenerator generatorRSA = KeyPairGenerator.getInstance("RSA"); generatorRSA.initialize(2048, new SecureRandom()); KeyPair keyRSA = generatorRSA.generateKeyPair(); DataInputStream pInRSA = new DataInputStream(new FileInputStream(inFile)); DataOutputStream eOutRSA = new DataOutputStream(new FileOutputStream("RSACipherText.txt")); encoderRSA = Cipher.getInstance("RSA/ECB/NoPadding"); encoderRSA.init(Cipher.ENCRYPT_MODE, keyRSA.getPublic()); blockSize = (2048 / 8) - 11; while (pInRSA.available() > 0) { buffer = new byte[Math.min(blockSize, pInRSA.available())]; for (int i = 0; i < buffer.length; i++) { buffer[i] = pInRSA.readByte(); } encodedMsg = encoderRSA.doFinal(buffer); eOutRSA.write(encodedMsg, 0, encodedMsg.length); } pInRSA.close(); eOutRSA.close(); DataInputStream eInRSA = new DataInputStream(new FileInputStream("RSACipherText.txt")); DataOutputStream pOutRSA = new DataOutputStream(new FileOutputStream("RSAPlainText.txt")); decoderRSA = Cipher.getInstance("RSA/ECB/NoPadding"); decoderRSA.init(Cipher.DECRYPT_MODE, keyRSA.getPrivate()); blockSize = encodedMsg.length; buffer = new byte[blockSize]; while (eInRSA.available() > 0) { for (int i = 0; i < blockSize; i++) { buffer[i] = eInRSA.readByte(); } decodedMsg = decoderRSA.doFinal(buffer); pOutRSA.write(decodedMsg, 0, decodedMsg.length); } eInRSA.close(); pOutRSA.close();
•
•
Join Date: Dec 2008
Posts: 53
Reputation:
Solved Threads: 6
0
#13 Oct 18th, 2009
•
•
•
•
I only compared the original text to the decrypted text at a glance, but it appeared to have worked. Below is my entire encryption/decryption process with RSA. Like I said, it appears to have worked great. Does it make sense to you?
Note you should never do this in real life. For example, try encrypting the following and seeing what the "encrypted" data looks like:
- a block of all zeroes
- a block of all zeroes except for the final byte in the array, which is set to 1
If you're encrypting multiple blocks with the same key, you should also never let the same plain text block result in the same encrypted block. This is what "block modes" are all about with genuine block ciphers. But note that in any case RSA is really not generally used this way: you generally just encrypt a single AES key (or some other key) at the start of the data, and then use that to encrypt the "real" data.
Last edited by neilcoffey; Oct 18th, 2009 at 7:25 pm.
![]() |
Similar Threads
- Java Encryption and Decryption (Java)
- Java Encryption and Decryption (Java)
- help recovering a word using RSA (Python)
- Forms in Random access files (Visual Basic 4 / 5 / 6)
- CD Burning Error: Block size does not correspond to image length (Windows NT / 2000 / XP)
- Java Encryption error (Java)
- Java Encryption (Elections System) (Java)
- aspect oriented project (Java)
Other Threads in the Java Forum
- Previous Thread: ComboBox Problem
- Next Thread: Null Pointer Exception Help
| Thread Tools | Search this Thread |
.net add addressbook ajax apple applet arguments automation binary block bold browser c++ character class classes code component derby design development developmenthelp eclipse ediscovery email encryption enterprise error file firefox fractal ftp game google gui guidancer html ideas image inheritance integer intellijidea8 java javafx javascript jetbrains jni jpanel jtable julia kmip laptop links linux loan machine macintosh method microsoft mysql netbeans newbie news officefileformats opensource password plazmic poi print problem program programming projectideas python reference researchinmotion scale security set size smart software solaris sort source sql string subclass sun support swing threads title tree user virus web webmail webservices windows






