Code example for SecretKeySpec

Methods: getEncoded

0
	    /* Derive the key, given password and salt. */ 
	    SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
	    KeySpec spec = new PBEKeySpec(password, salt, 65536, 128);
	    SecretKey tmp = factory.generateSecret(spec);
	    Log.e(TAG,tmp.getEncoded().length + " "+ new String(tmp.getEncoded()));
	    SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");
	    Log.e(TAG,secret.getEncoded().length + " "+ new String(secret.getEncoded()));
	    return secret.getEncoded();
	} 
	 
	 
	public static byte[] generatePBEKey(char[] password) throws NoSuchAlgorithmException, InvalidKeySpecException {
	    byte salt[] = new byte[16];
	    SecureRandom saltGen = SecureRandom.getInstance("SHA1PRNG");
	    saltGen.nextBytes(salt);
	    DropboxUtil.uploadFile(salt, Constants.SALT_FILE);
	    Log.e(TAG, "salt "+ salt);
	    //http://stackoverflow.com/questions/992019/java-256-bit-aes-password-based-encryption 
	    /* Derive the key, given password and salt. */ 
	    SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
	    KeySpec spec = new PBEKeySpec(password, salt, 65536, 128);