0

I'm trying to understand this comment from AES implementation code:

/**
 * This program generates a AES key, retrieves its raw bytes, and
 * then reinstantiates a AES key from the key bytes.
 * The reinstantiated key is used to initialize a AES cipher for
 * encryption and decryption.
 */

I don't understand following points:

  1. What does it mean by raw bytes of AES key?
  2. What does it mean by reinstantiates a AES key from the key bytes?
1
  • 1
    You're asking an awful lot of AES questions in rapid succession. Perhaps you need to spend a bit more time reading through the documentation thoroughly before turning to SO with every question?
    – Ether
    Nov 19, 2009 at 17:54

3 Answers 3

1

I think you are reading this web page,

http://java.sun.com/developer/technicalArticles/Security/AES/AES_v1.html

We have code that generates AES keys according to this example also but I think the author is a little bit confused. It generates keys like this,

    kgen = KeyGenerator.getInstance("AES");
        kgen.init(128);
        // Generate the secret key specs.
        SecretKey skey = kgen.generateKey();
        byte[] raw = skey.getEncoded();
        SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");

skey is already an AES key you can use. The second step does nothing. If you look inside skey and skeySpec, they are identical.

So you can ignore the explanation. It doesn't make it any more clear.

1

Raw bytes probably refers to the storage representation of the key object.
Usually you create a key object and then get a form in which to store it (have a look at java.security.Key#getEncoded(). That storage/exchange representation is a byte array without encoding information - therefore "raw bytes".

These raw bytes then can be used to instantiate the key object again.
Unclear to me is why the program reinstantiates the key object instead of using the one it created earlier.
That probably can only be answered by seeing the code of the program.

-1

AES: Advanced Encyption Standard The key is a string. So this seems to generate a string. It likely then converts it to an array of bytes (perhaps for storage). It then recreates the string from the array of bytes.

1
  • Actually, it generates an Key object, then gets its bytes and creates a KeySpec object from them. Aug 23, 2011 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.