How to write data in file in “unreadable” form?

The question was asked: 49 years 8 months ago   views: 3

Hello) I have to play (loudly) we need to make save/load) to Keep the data going in the file and read from it, respectively. How to write data in the file so that the user could not read the content (kvazary any), and the program when reading from this file would get the correct (=right obosnovanie) data? If you know another way to organize the save/load please write and razyasnit)

Asked: 01-01-1970 в 03:00:00

Answers   4


XOR on the string, and the string to pass or at the end or at the beginning, just to realize and solve not so simply as if you just XOR In each case, the string will be different which further complicates the reverse decryption to the attacker. Only the length of the string and its location will be identical and known to the author.

Answered: 24-12-2012 в 00:48:49

This is not the case where you need real encryption (usually in games it is), so the most appropriate option would be a simple and fast XOR-encryption.

Answered: 23-12-2012 в 20:55:31

And what's the problem? Just don't read people, can be in binary form to record. Can serialization be used ( by the way, and will Parmelee, for persistence ), can apply encoding functions and decoding, to write their own, a lot of options!

Answered: 23-12-2012 в 15:22:07

The answer is simple. To use encryption. For example, key. I personally like the AES algorithm. Here is an example of encryption:

/* Derive the key, given password and salt. */ SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); KeySpec spec = new PBEKeySpec(password, salt, 65536, 256); SecretKey tmp = the generatesecret(spec); SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES"); /* Encrypt the message. */ Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secret); AlgorithmParameters params = cipher.getParameters(); byte[] iv = params.getParameterSpec(IvParameterSpec.class).getIV(); byte[] ciphertext = cipher.doFinal("Hello, World!".getBytes("UTF-8"));

Transcript here:

/* Decrypt the message, given derived key and initialization vector. */ Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, secret, new IvParameterSpec(iv)); String plaintext = new String(cipher.doFinal(ciphertext), "UTF-8"); System.out.println(plaintext);

Taken from here

Answered: 23-12-2012 в 15:21:11
A common problem: the key where to stick it? - 23-12-2012 в 18:57:17
@Barmaley, in resources, if not essential, in the registry. all that is on your computer, you fundamentally intercept decrypted before use. can critical data for authorization logic and saves to be stored on the server. - 23-12-2012 в 20:36:58