private byte[] unpadOAEP(byte[] padded) throws BadPaddingException {
  byte[] EM=padded;
  boolean bp=false;
  int hLen=lHash.length;
  if (EM[0] != 0) {
    bp=true;
  }
  int seedStart=1;
  int seedLen=hLen;
  int dbStart=hLen + 1;
  int dbLen=EM.length - dbStart;
  mgf1(EM,dbStart,dbLen,EM,seedStart,seedLen);
  mgf1(EM,seedStart,seedLen,EM,dbStart,dbLen);
  for (int i=0; i < hLen; i++) {
    if (lHash[i] != EM[dbStart + i]) {
      bp=true;
    }
  }
  int padStart=dbStart + hLen;
  int onePos=-1;
  for (int i=padStart; i < EM.length; i++) {
    int value=EM[i];
    if (onePos == -1) {
      if (value == 0x00) {
      }
 else       if (value == 0x01) {
        onePos=i;
      }
 else {
        bp=true;
      }
    }
  }
  if (onePos == -1) {
    bp=true;
    onePos=EM.length - 1;
  }
  int mStart=onePos + 1;
  byte[] tmp=new byte[mStart - padStart];
  System.arraycopy(EM,padStart,tmp,0,tmp.length);
  byte[] m=new byte[EM.length - mStart];
  System.arraycopy(EM,mStart,m,0,m.length);
  BadPaddingException bpe=new BadPaddingException("Decryption error");
  if (bp) {
    throw bpe;
  }
 else {
    return m;
  }
}

private byte [ ] unpadOAEP ( byte [ ] padded ) throws BadPaddingException { byte [ ] EM = padded ; boolean bp = false ; int hLen = lHash . length ; if ( EM [ 0 ] != 0 ) { bp = true ; } int seedStart = 1 ; int seedLen = hLen ; int dbStart = hLen + 1 ; int dbLen = EM . length - dbStart ; mgf1 ( EM , dbStart , dbLen , EM , seedStart , seedLen ) ; mgf1 ( EM , seedStart , seedLen , EM , dbStart , dbLen ) ; for ( int i = 0 ; i < hLen ; i ++ ) { if ( lHash [ i ] != EM [ dbStart + i ] ) { bp = true ; } } int padStart = dbStart + hLen ; int onePos = - 1 ; for ( int i = padStart ; i < EM . length ; i ++ ) { int value = EM [ i ] ; if ( onePos == - 1 ) { if ( value == 0x00 ) { } else if ( value == 0x01 ) { onePos = i ; } else { bp = true ; } } } if ( onePos == - 1 ) { bp = true ; onePos = EM . length - 1 ; } int mStart = onePos + 1 ; byte [ ] tmp = new byte [ mStart - padStart ] ; System . arraycopy ( EM , padStart , tmp , 0 , tmp . length ) ; byte [ ] m = new byte [ EM . length - mStart ] ; System . arraycopy ( EM , mStart , m , 0 , m . length ) ; BadPaddingException bpe = new BadPaddingException ( "Decryption error" ) ; if ( bp ) { throw bpe ; } else { return m ; } }
pkcs # 1 v2 . 1 oaep unpadding ( mgf1 ) .
