private byte[] unpadV15(byte[] padded) throws BadPaddingException {
  int k=0;
  boolean bp=false;
  if (padded[k++] != 0) {
    bp=true;
  }
  if (padded[k++] != type) {
    bp=true;
  }
  int p=0;
  while (k < padded.length) {
    int b=padded[k++] & 0xff;
    if ((b == 0) && (p == 0)) {
      p=k;
    }
    if ((k == padded.length) && (p == 0)) {
      bp=true;
    }
    if ((type == PAD_BLOCKTYPE_1) && (b != 0xff) && (p == 0)) {
      bp=true;
    }
  }
  int n=padded.length - p;
  if (n > maxDataSize) {
    bp=true;
  }
  byte[] padding=new byte[p];
  System.arraycopy(padded,0,padding,0,p);
  byte[] data=new byte[n];
  System.arraycopy(padded,p,data,0,n);
  BadPaddingException bpe=new BadPaddingException("Decryption error");
  if (bp) {
    throw bpe;
  }
 else {
    return data;
  }
}

private byte [ ] unpadV15 ( byte [ ] padded ) throws BadPaddingException { int k = 0 ; boolean bp = false ; if ( padded [ k ++ ] != 0 ) { bp = true ; } if ( padded [ k ++ ] != type ) { bp = true ; } int p = 0 ; while ( k < padded . length ) { int b = padded [ k ++ ] & 0xff ; if ( ( b == 0 ) && ( p == 0 ) ) { p = k ; } if ( ( k == padded . length ) && ( p == 0 ) ) { bp = true ; } if ( ( type == PAD_BLOCKTYPE_1 ) && ( b != 0xff ) && ( p == 0 ) ) { bp = true ; } } int n = padded . length - p ; if ( n > maxDataSize ) { bp = true ; } byte [ ] padding = new byte [ p ] ; System . arraycopy ( padded , 0 , padding , 0 , p ) ; byte [ ] data = new byte [ n ] ; System . arraycopy ( padded , p , data , 0 , n ) ; BadPaddingException bpe = new BadPaddingException ( "Decryption error" ) ; if ( bp ) { throw bpe ; } else { return data ; } }
pkcs # 1 v1 . 5 unpadding ( blocktype 1 ( signature ) and 2 ( encryption ) ) . note that we want to make it a constant - time operation
