Java Cryptography with AES, how does it work?

7

I have already found several examples by Google, but none that explain how a java cryptography works with AES ... How does it work?

In an example of the net, the guy cites that he has to use a key, but does not explain why or what it is for;

ex:

public static final byte[] CHAVE = {85, 10, 0, -25, 68, 88, 46, 37, 107, 48, 10, -1, -37, -90, 70, -36};

What is the key for? Can it be any value? What does this AES have different from others? Does it work on Android?

Edit: After a conversation in the comments, I understood that I have to use a static key, because I will use it in a game, just to save a value using shared pref. of Android. This value is the highest rank of the player!

But it still fits my question, can it be any value? I understood nothing of this example (the key I posted) ...

    
asked by anonymous 06.05.2014 / 21:44

1 answer

5

Cryptographic keys are what define the output of the encryption algorithm. They are defined in bits. As in most programming languages the smallest possible unit is the byte, they are represented by bytes. One byte equals eight bits, so a 128-bit key will have 16 bytes.

You should not choose the key, you should not even get a key on the web. You should use a secure cryptographic key generator, which will generate a random key and will ensure that the key has a high entropy.

In Java, one way to generate this is:

KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(256); // Tamanho da chave como exemplo.
SecretKey secretKey = keyGen.generateKey();

Your other issue, as stated in the comments, concerns the safety of mobile games. This is a complex issue that involves different factors and depends on the technology used. Take into account that it is very difficult to create a completely safe game. Most of the most popular games in app stores have security holes.

    
20.05.2014 / 19:55