import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; import sun.misc.BASE64Encoder; // Author: duxZero public class Online { // your private key private final static String key = "12345678"; // the url of your php fie private final static String php = "http://website.com/online/index.php"; private static String encrypt(String data) throws Exception { DESKeySpec keySpec; keySpec = new DESKeySpec(key.getBytes("UTF8")); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey key = keyFactory.generateSecret(keySpec); sun.misc.BASE64Encoder base64encoder = new BASE64Encoder(); Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.ENCRYPT_MODE, key); String encrypted = base64encoder.encode(cipher.doFinal(data .getBytes("UTF8"))); return encrypted; } private static String send_data(String data) throws Exception { String str = "?data=" + URLEncoder.encode(data, "UTF8"); URL url = new URL(php + str); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter( conn.getOutputStream()); writer.flush(); BufferedReader reader = new BufferedReader(new InputStreamReader( conn.getInputStream())); String repsone = reader.readLine(); writer.close(); reader.close(); return repsone; } public static String add_user(String username, String script) { String repsone = null; String data = "{\"do\": \"add\", \"username\": \"" + username + "\", \"script\": \"" + script + "\"}"; try { String encrypted = encrypt(data); repsone = send_data(encrypted); } catch (Exception e) { return e.toString(); } return repsone; } public static String remove_user(String username, String script) { String repsone = null; String data = "{\"do\": \"remove\", \"username\": \"" + username + "\", \"script\": \"" + script + "\"}"; try { String encrypted = encrypt(data); repsone = send_data(encrypted); } catch (Exception e) { return e.toString(); } return repsone; } }