code: public static byte[] encrypt(PublicKey key, byte[] plainBytes) {
  
      	ByteArrayOutputStream out = null;
          try {
              Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
              cipher.init(Cipher.ENCRYPT_MODE, key);
              
              int inputLen = plainBytes.length;  
              if(inputLen <= MAX_ENCRYPT_BLOCK){
              	return cipher.doFinal(plainBytes);
              }
              out = new ByteArrayOutputStream();  
              int offSet = 0;  
              byte[] cache;  
              int i = 0;  
              // 对数据分段加密  
              while (inputLen - offSet > 0) {  
                  if (inputLen - offSet > MAX_ENCRYPT_BLOCK) {  
                      cache = cipher.doFinal(plainBytes, offSet, MAX_ENCRYPT_BLOCK);  
                  } else {  
                      cache = cipher.doFinal(plainBytes, offSet, inputLen - offSet);  
                  }  
                  out.write(cache, 0, cache.length);  
                  i++;  
                  offSet = i * MAX_ENCRYPT_BLOCK;  
              }  
              return out.toByteArray();
          } catch (NoSuchAlgorithmException e) {  
              throw new RuntimeException("无此解密算法");  
          } catch (NoSuchPaddingException e) {  
              e.printStackTrace();  
              return null;  
          } catch (InvalidKeyException e) {  
              throw new RuntimeException("解密私钥非法,请检查");  
          } catch (IllegalBlockSizeException e) {  
              throw new RuntimeException("密文长度非法");  
          } catch (BadPaddingException e) {  
              throw new RuntimeException("密文数据已损坏");  
          }finally{
          	try {if(out != null)out.close(); } catch (Exception e2) {}
          }
      }
docs: 加密
  
  @param key
  @param plainBytes
  @return