private byte[] generateDerivedKey(int idByte,int n){
  byte[] D=new byte[v];
  byte[] dKey=new byte[n];
  for (int i=0; i != D.length; i++) {
    D[i]=(byte)idByte;
  }
  byte[] S;
  if ((salt != null) && (salt.length != 0)) {
    S=new byte[v * ((salt.length + v - 1) / v)];
    for (int i=0; i != S.length; i++) {
      S[i]=salt[i % salt.length];
    }
  }
 else {
    S=new byte[0];
  }
  byte[] P;
  if ((password != null) && (password.length != 0)) {
    P=new byte[v * ((password.length + v - 1) / v)];
    for (int i=0; i != P.length; i++) {
      P[i]=password[i % password.length];
    }
  }
 else {
    P=new byte[0];
  }
  byte[] I=new byte[S.length + P.length];
  System.arraycopy(S,0,I,0,S.length);
  System.arraycopy(P,0,I,S.length,P.length);
  byte[] B=new byte[v];
  int c=(n + u - 1) / u;
  byte[] A=new byte[u];
  for (int i=1; i <= c; i++) {
    digest.update(D,0,D.length);
    digest.update(I,0,I.length);
    digest.doFinal(A,0);
    for (int j=1; j < iterationCount; j++) {
      digest.update(A,0,A.length);
      digest.doFinal(A,0);
    }
    for (int j=0; j != B.length; j++) {
      B[j]=A[j % A.length];
    }
    for (int j=0; j != I.length / v; j++) {
      adjust(I,j * v,B);
    }
    if (i == c) {
      System.arraycopy(A,0,dKey,(i - 1) * u,dKey.length - ((i - 1) * u));
    }
 else {
      System.arraycopy(A,0,dKey,(i - 1) * u,A.length);
    }
  }
  return dKey;
}

private byte [ ] generateDerivedKey ( int idByte , int n ) { byte [ ] D = new byte [ v ] ; byte [ ] dKey = new byte [ n ] ; for ( int i = 0 ; i != D . length ; i ++ ) { D [ i ] = ( byte ) idByte ; } byte [ ] S ; if ( ( salt != null ) && ( salt . length != 0 ) ) { S = new byte [ v * ( ( salt . length + v - 1 ) / v ) ] ; for ( int i = 0 ; i != S . length ; i ++ ) { S [ i ] = salt [ i % salt . length ] ; } } else { S = new byte [ 0 ] ; } byte [ ] P ; if ( ( password != null ) && ( password . length != 0 ) ) { P = new byte [ v * ( ( password . length + v - 1 ) / v ) ] ; for ( int i = 0 ; i != P . length ; i ++ ) { P [ i ] = password [ i % password . length ] ; } } else { P = new byte [ 0 ] ; } byte [ ] I = new byte [ S . length + P . length ] ; System . arraycopy ( S , 0 , I , 0 , S . length ) ; System . arraycopy ( P , 0 , I , S . length , P . length ) ; byte [ ] B = new byte [ v ] ; int c = ( n + u - 1 ) / u ; byte [ ] A = new byte [ u ] ; for ( int i = 1 ; i <= c ; i ++ ) { digest . update ( D , 0 , D . length ) ; digest . update ( I , 0 , I . length ) ; digest . doFinal ( A , 0 ) ; for ( int j = 1 ; j < iterationCount ; j ++ ) { digest . update ( A , 0 , A . length ) ; digest . doFinal ( A , 0 ) ; } for ( int j = 0 ; j != B . length ; j ++ ) { B [ j ] = A [ j % A . length ] ; } for ( int j = 0 ; j != I . length / v ; j ++ ) { adjust ( I , j * v , B ) ; } if ( i == c ) { System . arraycopy ( A , 0 , dKey , ( i - 1 ) * u , dKey . length - ( ( i - 1 ) * u ) ) ; } else { System . arraycopy ( A , 0 , dKey , ( i - 1 ) * u , A . length ) ; } } return dKey ; }
generation of a derived key ala pkcs12 v1 . 0 .
