• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java AES file encryption (one last problem on output File)  RSS feed

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PROBLEM: I have everything set-up encryption method itself is built fine I believe I know this because when I call my method encrypt(inputFile, new File("Users/myname/Desktop/example.txt"),key); This is writing to my desktop indeed but what I'm trying to do is instead of the "Users/myname/Desktop/example.txt" and writing the file here I'm trying to pass it to upload to dropBox... I'll explain with my code below. So question I'm presenting is how to pass the ' File output ' from encrypt method so it can be uploaded to dropbox. I have been working on this the better part of the day, I know its probably something simple? I just need someone objectively point out whats going on and correct the problem so I can learn and be able to put the blocks together for future projects, thank you



 
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I believe with "DropBox":

If I understand DropBox it is a web service, not a locally controlled section of you local file system, so you will need to be able to have a "catcher" on the other side of the pipe so you can have your data accepted by the server and reassembled into your file. The simple Java streams will not support that. You have to have a look at the DropBox API and see what protocols you will have to follow or implement to make this work.

Les
 
travis Haycock
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should rephrase the question I believe I now have it working to and extent the problem is this though






So as you can see the path /Users/travis/Desktop/aesTest.png" is taking the form of the new file that I chose with JFileChooser but is there a way instead of writing in the complete path to use a Var somehow so I would manually not have to do this as its not practical in real work? something like this (does not work)



Apologies didn't mean to make it sound like i was having upload troubles everything is fine on that end its just the path I'm trying to solve so its more practical for myself and future users, thank you.
 
travis Haycock
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it... was just over looking the code too quick and was trying to get fancy when there was no need. inputFile.getnName() did the trick and sae thing with decrypt... ""dec"+ outputFile.getName() worked just fine... now to get it to automatically to save to users desktop regardless of file or OS
 
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
travis Haycock wrote:I have everything set-up encryption method itself is built fine I believe

You're using the key bytes for the IV. The IV should be randomly generated separately for every encryption operation, and then sent to the receiver together with your encrypted message.

I also recommend using authenticated encryption, like AES in Galois Counter Mode. The corresponding transformation is "AES/GCM/NoPadding".

Finally, use Path instead of File and use try-with-resources:
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!