• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

trying to encrypt image using RSA but its not encrypting ?

 
Ranch Hand
Posts: 47
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello friends ,

i am trying to encrypt the image file using the RSA algorithm
it doesn't show the error
but the output encrypted file is 0 bytes in size
it means something goes wrong

help me to solve this

following is the code
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Several points -

1) In its basic form the maximum length that RSA can encrypt at a time is limited to the size of the RSA modulus (or the modulus length - 11 when using PKCS11 padding by using the default padding as you are doing). One can break the input into blocks of less than this modulus and encrypt them individually but then one has to handle the problem problem that in RSA N bytes of cleartext does not necessarily produce N bytes of ciphertext..

When encrypting more than the RSA length one normally creates a hybrid encryption. In this approach one generates a random key for use with a block cipher such as AES and then uses this to encrypt the actual data. The random block cipher key is encrypted with RSA and sent with the AES cipher text. This approach is presented more formally in section 13.6 pf "Practical Cryptography" by Ferguson and Schneier.

2) In my view CipherInputStream and CipherOutputStream are very poor. They swallow all exceptions so when anything goes wrong one never hears of it.

3) Chaining streams as you have done makes it difficult to read the code and if anything goes wrong it is difficult to work out which term in the chain caused the exception. It costs nothing to use something like


4) I'm never very comfortable with reading and writing just one byte at a time using


I have known this to fail. You would do better to read and write a chunk (say 4K) at a time.

 
sanket jani
Ranch Hand
Posts: 47
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your valuable answer
i will retry it .
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic