title: Generate SecretKey from AndroidKeyStore
body: <p>According to this <a href="http://www.programcreek.com/java-api-examples/index.php?api=android.security.keystore.KeyProperties" rel="nofollow">sample</a>, I am trying to get <code>SecretKey</code> from <code>AndroidKeyStore</code>:</p>
  
  <pre><code>KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
  keyStore.load(null);
  SecretKey secretKey = (SecretKey) keyStore.getKey(KEY_NAME, null);
  </code></pre>
  
  <p>But I get this exception:</p>
  
  <pre><code>android.security.keystore.AndroidKeyStoreRSAPrivateKey cannot be cast to javax.crypto.SecretKey
  </code></pre>
  
  <p>This is how I have created the key:</p>
  
  <pre><code>KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(context)
                      .setAlias(KEY_NAME)
                      .setSubject(new X500Principal("CN=" + KEY_NAME))
                      .setSerialNumber(BigInteger.valueOf(1337))
                      .setStartDate(START_TIME)
                      .setEndDate(END_TIME)
                      .build();
  KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore");   
  kpGenerator.initialize(spec);
  kpGenerator.generateKeyPair();
  </code></pre>
  
  <p>So is there any way to generate <code>SecretKey</code> from <code>AndroidKeyStore</code>?</p>