• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

how will be a java program which would split the file and encrypt the splitted files automatically.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do help me to know how can i develop a java program which would split the file selected by user and then encrypt those splitted file parts using encryption algorithm.
 
Marshal
Posts: 79977
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

We do not give complete solutions, so please show us what you have got at the moment and we shall suggest how you can improve it.
 
swapnali more
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a java program which split the file into parts based on the chunk size. The file gets splitted by name text.01.txt, test.02.txt. But now i want to encrypt those splitted files so i am confused how should i do that. How can i retrieve those files and perform encryption on those files one by one. All this work of splitting file and encrypting parts should take place internally , the user will only select the file and rest of this should take palce internally Please do let me know..Need help..thanks..
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post your code and UseCodeTags (<- that's a link).
 
swapnali more
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My code for file splitting is as follow..Please tell me how should i retrieve those splitted files to perform encryption on them. I have an AES encryption java program too..how should i call those files for encryption process.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code is formatted very oddly. Use tabs to indent with only a maximum of eight spaces per tab. Don't double space. You can leave a space between methods. Here is a suggested style guide. This may seem like nit picking, but it's not. Bad formatting makes your code hard to read.

Here is a webpage that shows you how to add AES encryption. Give it a try and post what you get.
 
Campbell Ritchie
Marshal
Posts: 79977
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have text files why are you using streams rather than Scanner and Formatter?
 
Saloon Keeper
Posts: 15731
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't do encryption with AES only. Encryption is often vulnerable without authentication. Use an AEAD algorithm instead.

Java's Cipher.getInstance() class supports the "AES/GCM/NoPadding" transformation, which is an AEAD algorithm.
 
Stephan van Hulst
Saloon Keeper
Posts: 15731
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:Here is a webpage that shows you how to add AES encryption. Give it a try and post what you get.



Please don't use this algorithm, it

  • hard-codes the key,
  • handles the key as a String and not a char array,
  • uses SHA as a key derivation algorithm,
  • doesn't employ authentication,
  • uses electronic code book mode.


  • I think I will write a guide on how to do password-based encryption for general use cases.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 15731
    368
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Also, mutable static fields? That isn't even proper code if we forget about the encryption problems.
     
    Knute Snortum
    Sheriff
    Posts: 7125
    184
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Well that's what I get for Google and Paste.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 15731
    368
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Crypto is notoriously hard. Even with a more thorough Google search will you find lots of bad example code.

    The problem is that it looks easy to use crypto to get a result that looks correct, but there are actually a lot of pitfalls.
     
    swapnali more
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    do guide me how can i retrieve or use the splitted files from the folder and encrypt them one by one...how should i call those files for encryption ...which method will help me to do so...please do let me know..
     
    Campbell Ritchie
    Marshal
    Posts: 79977
    397
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Moved to our security forum.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 15731
    368
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Well, it completely depends on the context.

    You want to encrypt and decrypt using a password. If you have a system that users can log in to, you can do this simply by first authenticating the user, and then using their stored key to encrypt and decrypt files. If you don't have a log in system, you have to derive a key from their password on every encrypt and decrypt operation.

    I'm going to assume the second case. Here are the steps you have to take for one encryption operation:

  • Generate a salt and an initialization vector (IV) using a cryptographically secure pseudo-random number generator.
  • Derive a key from a pass phrase, salt and iteration count using a key derivation function, such as PBKDF2.
  • Encrypt the file with the key and the IV using an AEAD algorithm such as AES-GCM.
  • Add the salt, iteration count and IV to the message in clear.

  • Here are the steps for one decryption operation;

  • Remove the salt, iteration count and the IV from the message.
  • Derive a key from a pass phrase, stored salt and iteration count using the same key derivation function you used when you encrypted the file.
  • Decrypt the file with the key and the stored IV using the AEAD algorithm you used when you encrypted the file.

  • For both of these operations, keys, salts, and IVs should be stored as byte arrays. Pass phrases should be stored as char arrays. Keys and pass phrases should be zeroed out once you're done with them.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 15731
    368
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I recommend that you first decide on a format for your file chunks. Since textual data is easier to debug, a chunk "text.01.txt" could look something like this:

     
    Not so fast naughty spawn! I want you to know about
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic