title: Android KeyPairGenerator always generates the same key pair
body: <p>I am making an application which generates a <strong>key pair</strong> for a user. But in every device the keys are identical. Here is my code:</p>
  
  <pre><code>public KeyPair generateKeys() {
      KeyPair keyPair = null;
      try {
          // get instance of rsa cipher
          KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
          keyGen.initialize(1024);            // initialize key generator
          keyPair = keyGen.generateKeyPair(); // generate pair of keys
      } catch(GeneralSecurityException e) {
          System.out.println(e); 
      }
      return keyPair;
  }
  </code></pre>
  
  <p>And to show the generated keys code is:</p>
  
  <pre><code>KeyPair keyPair = rsa.generateKeys();
  
  byte[] publicKey = keyPair.getPublic().getEncoded();
  byte[] privateKey = keyPair.getPrivate().getEncoded();
  privateText.setText( Base64.encodeToString(privateKey, Base64.NO_WRAP) );
  publicText.setText( Base64.encodeToString(publicKey, Base64.NO_WRAP) );
  </code></pre>
  
  <p>The key generation is called only one time for each android device, and for that reason the keys in each device should be different.. Can anyone tell me what i am missing here?</p>