title: Generate AES key through IAIK PKCS#11 wrapper and show its value
body: <p>I would like to use PKCS#11 compatible cryptographic USB token to generate AES key and show its value on screen.</p>
  
  <p>For that purpose I want to use IAIK PKCS#11 wrapper.</p>
  
  <p>I tried to generate the key by the example provided with IAIK package but with no success. The key is generated but I can't see any value of key. What should I do to see the key value in order to show it on screen?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Module pkcs11Module = null;
  pkcs11Module = Module.getInstance("pkcs11.dll");
  
  Session session = null;
  pkcs11Module.initialize(null);
  
  Slot[] slots = pkcs11Module.getSlotList(Module.SlotRequirement.TOKEN_PRESENT);
  
  if (slots.length == 0) {
      output_.println("No slot with present token found!");
      throw new TokenException("No token found!");
  }
  
  Slot selectedSlot;
  // slot 0
  selectedSlot = slots[0];
  
  Token token = selectedSlot.getToken();
  
  session = token.openSession(Token.SessionType.SERIAL_SESSION, Token.SessionReadWriteBehavior.RW_SESSION, null, null);
  
  session.login(Session.UserType.USER, "12345678".toCharArray());
  
  Mechanism keyGenerationMechanism = Mechanism.get(PKCS11Constants.CKM_AES_KEY_GEN);
  
  AESSecretKey aesKey = new AESSecretKey();
  aesKey.getValueLen().setLongValue(new Long(32));
  
  AESSecretKey aesKeyNew = (AESSecretKey) session.generateKey(keyGenerationMechanism, aesKey);
  output_.println("the AES Key is: ");
  output_.println(aesKeyNew.toString());
  
  session.closeSession();
  pkcs11Module.finalize(null);
  </code></pre>
  
  <p>The results is as follows:</p>
  
  <pre><code>the AES Key is: 
    Object Class: Secret Key
    Token: false
    Private: false
    Modifiable: true
    Label: &lt;NULL_PTR&gt;
    Key Type: AES
    ID: &lt;NULL_PTR&gt;
    Start Date: &lt;NULL_PTR&gt;
    End Date: &lt;NULL_PTR&gt;
    Derive: true
    Local: true
    Key Generation Mechanism: CKM_AES_KEY_GEN
    Allowed Mechanisms: &lt;Attribute not present&gt;
    Sensitive: false
    Encrypt: true
    Decrypt: true
    Sign: false
    Verify: false
    Wrap: true
    Unwrap: true
    Extractable: true
    Always Sensitive: false
    Never Extractable: true
    Check Value: &lt;Attribute not present&gt;
    Wrap With Trusted: &lt;Attribute not present&gt;
    Trusted: &lt;Attribute not present&gt;
    Wrap Template: &lt;Attribute not present&gt;
    Unwrap Template: &lt;Attribute not present&gt;
    Value (hex): &lt;NULL_PTR&gt;
    Value Length (dec): 0
  </code></pre>
  
  <p>There is Value (hex):  that I want to see and show on screen.
  Is it about a specific configuration of cryptographic tokens? When I use different token then I see this value.</p>