public static byte[] encode(byte[] data,String pub_key){
  try {
    Cipher cipher=Cipher.getInstance("RSA/ECB/PKCS1Padding");
    java.security.Key k=getPublicKey(pub_key);
    cipher.init(Cipher.ENCRYPT_MODE,k);
    byte[] enBytes=cipher.doFinal(data);
    return enBytes;
  }
 catch (  Exception e) {
    log.error("pubkey=" + pub_key + ", data.length="+ data.length,e);
  }
  return null;
}

public static byte [ ] encode ( byte [ ] data , String pub_key ) { try { Cipher cipher = Cipher . getInstance ( "RSA/ECB/PKCS1Padding" ) ; java . security . Key k = getPublicKey ( pub_key ) ; cipher . init ( Cipher . ENCRYPT_MODE , k ) ; byte [ ] enBytes = cipher . doFinal ( data ) ; return enBytes ; } catch ( Exception e ) { log . error ( "pubkey=" + pub_key + ", data.length=" + data . length , e ) ; } return null ; }
encode the data with the public key .
