title: How to save Oauth Access token securely in android
body: <p>I have access token from the server after authentication lets say <code>"uyhjjfjfgg567f8fhjkkf"</code> now I want to save it in the device securely. I looked in Keystore and Keychain in android developer sites. I dont clearly understand how it works and how we should retrieve the token from the keystore. </p>
  
  <pre><code>KeyPairGenerator kpg = KeyPairGenerator.getInstance(
          KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore");
  kpg.initialize(new KeyGenParameterSpec.Builder(
          alias,
          KeyProperties.PURPOSE_SIGN | KeyProperties.PURPOSE_VERIFY)
          .setDigests(KeyProperties.DIGEST_SHA256,
              KeyProperties.DIGEST_SHA512)
          .build());
  
  KeyPair kp = kpg.generateKeyPair();
  
  
  /*
   * Load the Android KeyStore instance using the the
   * "AndroidKeyStore" provider to list out what entries are
   * currently stored.
   */
  
  KeyStore ks = KeyStore.getInstance("AndroidKeyStore");
  ks.load(null);
  Enumeration&lt;String&gt; aliases = ks.aliases();
  </code></pre>