Results 1 to 5 of 5
  1. #1
    counterfox is offline Member
    Join Date
    Mar 2009
    Posts
    45
    Rep Power
    0

    Default Java encyption for text files

    Hi all,

    for my project I've created a simple java game which has save/load functions. I plan for my save to pretty much just copy loads of variables from the game into a text file which can be read from the load.

    However if someone accesses the text file then they can easily change the values which isn't really the point of save/load.

    Is there any way to encrypt the text file or anything (it can be really simple) or any ideas of the best way to keep a basic security for the text file.

    Thanks in advance.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,568
    Rep Power
    12

    Default

    If you asked Google this question you would probably get any amount of information about techniques that other people actually use.

    Perhaps you did better to ask here! Where you get a human response: concerned as much about you as about the encryption task. My response would have to be "How would you do this by hand?" In other words if you had some textual information that you accepted would be physically accessible to anyone, how would you encrypt it so that it would be unreadable? (Think of a notebook with passwords in it, or a diary)

    Once you have some plan you could post it here for people to find fault with (and, thereby improve). When (and only when) you have plan that you're happy with you can start implementing it with code - at which point you might have specific questions to ask.

    Just my 2c.

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    You can encrypt, but probably a much simpler method that would be good enough, would be to simply use Object Serialization. It'll save a ton of work with regards to writing and reading variables (it skips that all together) and it produces a binary file which will be largely illegible. Might be much easier to get into than encryption.

  4. #4
    counterfox is offline Member
    Join Date
    Mar 2009
    Posts
    45
    Rep Power
    0

    Default

    Hi everyone,

    Thanks for your replies.

    The only problem is that for my project were not allowed to use the serialization interface in my project (im guessing as it saves alot of trouble and they want us to show a solution by ourselves).

    I'm pretty new to java so might be bad but heres what I thought:

    As I've got to write save/load without the help of javas serialization, I was going to have a folder which is called saved games or something.
    Then I was going to create a new class called "GameState" which is essentially every variable I'd need to save. Then for each class based on the game I was going to copy these onto one line of the file. (each line would be the variables of one of the classes).

    So for example say I have three classes' variables which need to be saved, it will be all be in one text file but on three lines. So pretty much on every saved game there will be one text file created.

    Then when loads made I can read the lines one by one and load it back into the appriopiate objects of the three classes.

    My other idea was to put every saved game on one line (so theres one text file for all saved games, but I think it would be really hard to write back into the objects when load is called as there are so many variables to be saved.

    Going back to the possible encryption I was thinking when the lines are being created, before its written maybe instead of using encryption, I would maybe convert it to bytes or something thats hard to read by humans. I was talking to a course mate and they said that the security on the file can be very basic as long as values can't be changed easily so I thought maybe a encryption might be to much and maybe theres a simple way to do it.

    Sorry I went onto the save/load but I'm sort of stuck on that aswel thought I'd see what people thought about it.

    Might not work or be completely wrong but thats the easiest idea I can think of at the moment.

    Please let me know what you think.

    Thanks in advance
    Last edited by counterfox; 02-13-2011 at 05:32 PM.

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Seems to me you and 'newToJava3' are doing the same project. Have you been reading his page too? Ways of doing save for a java game

Similar Threads

  1. Replies: 7
    Last Post: 04-10-2010, 12:46 PM
  2. working with files (text files)
    By itaipee in forum New To Java
    Replies: 1
    Last Post: 02-24-2009, 12:38 PM
  3. Behaving text files like binary files
    By Farzaneh in forum New To Java
    Replies: 2
    Last Post: 08-27-2008, 04:20 PM
  4. Does OS intervene when reading Java text files
    By Tina G in forum Advanced Java
    Replies: 1
    Last Post: 04-07-2008, 03:29 PM
  5. Text and image files within jar files
    By erhart in forum Advanced Java
    Replies: 8
    Last Post: 01-19-2008, 05:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •