public static CipherParameters makePBEMacParameters(BCPBEKey pbeKey,AlgorithmParameterSpec spec){
  if ((spec == null) || !(spec instanceof PBEParameterSpec)) {
    throw new IllegalArgumentException("Need a PBEParameter spec with a PBE key.");
  }
  PBEParameterSpec pbeParam=(PBEParameterSpec)spec;
  PBEParametersGenerator generator=makePBEGenerator(pbeKey.getType(),pbeKey.getDigest());
  byte[] key=pbeKey.getEncoded();
  CipherParameters param;
  if (pbeKey.shouldTryWrongPKCS12()) {
    key=new byte[2];
  }
  generator.init(key,pbeParam.getSalt(),pbeParam.getIterationCount());
  param=generator.generateDerivedMacParameters(pbeKey.getKeySize());
  for (int i=0; i != key.length; i++) {
    key[i]=0;
  }
  return param;
}

public static CipherParameters makePBEMacParameters ( BCPBEKey pbeKey , AlgorithmParameterSpec spec ) { if ( ( spec == null ) || ! ( spec instanceof PBEParameterSpec ) ) { throw new IllegalArgumentException ( "Need a PBEParameter spec with a PBE key." ) ; } PBEParameterSpec pbeParam = ( PBEParameterSpec ) spec ; PBEParametersGenerator generator = makePBEGenerator ( pbeKey . getType ( ) , pbeKey . getDigest ( ) ) ; byte [ ] key = pbeKey . getEncoded ( ) ; CipherParameters param ; if ( pbeKey . shouldTryWrongPKCS12 ( ) ) { key = new byte [ 2 ] ; } generator . init ( key , pbeParam . getSalt ( ) , pbeParam . getIterationCount ( ) ) ; param = generator . generateDerivedMacParameters ( pbeKey . getKeySize ( ) ) ; for ( int i = 0 ; i != key . length ; i ++ ) { key [ i ] = 0 ; } return param ; }
generate a pbe based key suitable for a mac algorithm , the key size is chosen according the mac size , or the hashing algorithm , whichever is greater .
