Tampilkan postingan dengan label Security. Tampilkan semua postingan
Tampilkan postingan dengan label Security. Tampilkan semua postingan

Rabu, 17 Oktober 2012

Simple Encryption Aplications Using AES and MD5 ( Aplikasi Enkripsi Sederhana Menggunakan AES dan MD5 )

Ok, this time I'll share about simple apps for encryption using AES and MD5. I try to combine AES with MD5. The string will be encrypted with AES first, and then the cipher text will be encrypted again with MD5. So, this is the capture of the applications.
The first field is for key encryption, and the second field is for the teks to be encrypted.
To create this app, I use 3 classes. The first class is an activity called AesMd5.java, GenerateAes.java, Md5Baru.java.
For the source code  to create this simple apps I'll show below.
The first is
AesMd5.java

package org.aesmd5;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.*;
import android.widget.Button;
import android.widget.EditText;

public class AesMd5 extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_aes_md5);
       
        final Button enkripButton = (Button)findViewById(R.id.enkrip_button);
        final EditText inputKunci = (EditText)findViewById(R.id.input_kunci);
        final EditText inputKata = (EditText)findViewById(R.id.input_kata);
        final EditText teksEnkrip = (EditText)findViewById(R.id.teks_enkrip);
        // handling for Encryption
        enkripButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                String ambilKunci = inputKunci.getText().toString();
                String ambilKata = inputKata.getText().toString();
                String enKata = "";
                try {
                    enKata = GenerateAES.encrypt(ambilKunci, ambilKata);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                //teksEnkrip.setText(enKata);
                teksEnkrip.setText(Md5Baru.MD5(enKata));
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_aes_md5, menu);
        return true;
    }
}


GenerateAes.java

package org.aesmd5;

import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.SecureRandom;

public class GenerateAES {
    //private Cipher cipher;
    //private SecretKeySpec sKey;
    public GenerateAES() {
    }
   
    public static String encrypt(String seed, String cleartext) throws Exception {
        byte[] rawKey = getRawKey(seed.getBytes());
        byte[] result = encrypt(rawKey, cleartext.getBytes());
        return toHex(result);
}

public static String decrypt(String seed, String encrypted) throws Exception {
        byte[] rawKey = getRawKey(seed.getBytes());
        byte[] enc = toByte(encrypted);
        byte[] result = decrypt(rawKey, enc);
        return new String(result);
}

private static byte[] getRawKey(byte[] seed) throws Exception {
        KeyGenerator kgen = KeyGenerator.getInstance("AES");
        SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
        sr.setSeed(seed);
    kgen.init(128, sr); // 192 and 256 bits may not be available
    SecretKey skey = kgen.generateKey();
    byte[] raw = skey.getEncoded();
    return raw;
}


private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
    SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
        Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
    byte[] encrypted = cipher.doFinal(clear);
        return encrypted;
}

private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
    SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
        Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.DECRYPT_MODE, skeySpec);
    byte[] decrypted = cipher.doFinal(encrypted);
        return decrypted;
}

public static String toHex(String txt) {
        return toHex(txt.getBytes());
}

public static byte[] toByte(String hexString) {
        int len = hexString.length()/2;
        byte[] result = new byte[len];
        for (int i = 0; i < len; i++)
                result[i] = Integer.valueOf(hexString.substring(2*i, 2*i+2), 16).byteValue();
        return result;
}

public static String toHex(byte[] buf) {
        if (buf == null)
                return "";
        StringBuffer result = new StringBuffer(2*buf.length);
        for (int i = 0; i < buf.length; i++) {
                appendHex(result, buf[i]);
        }
        return result.toString();
}
private final static String HEX = "0123456789ABCDEF";
private static void appendHex(StringBuffer sb, byte b) {
        sb.append(HEX.charAt((b>>4)&0x0f)).append(HEX.charAt(b&0x0f));
}
}


Md5Baru.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.aesmd5;
import java.security.*;
/**
 *
 * @author nang
 */
public class Md5Baru {

    public static String MD5(String text) {
        String md5 = "";
        byte test[] = text.getBytes();
        int panjang = 16;
        byte[] mesDig = new byte[panjang];
        try {
        MessageDigest mD = MessageDigest.getInstance("MD5");
        mD.reset();
        mD.update(text.getBytes(), 0, text.length());
        mD.digest(mesDig, 0, panjang);
        StringBuffer sB = new StringBuffer();
        for(int i=0; i<mesDig.length;i++) {
            //mesDig = mD.digest(test, 0, test.length);
            String hex = Integer.toHexString(0xFF & mesDig[i]);
            if(hex.length() == 1) {
                sB.append('0');
            }
            sB.append(hex);
        }
        md5 = sB.toString();
        } catch (Exception e){

        }
        return md5;
    }
}

And the last is activity_aes_md5.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TextView
        android:id="@+id/teks_kunci"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Masukkan kunci"
        />
    <EditText
        android:id="@+id/input_kunci"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/teks_kata"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Masukkan kata"
        />
    <EditText
        android:id="@+id/input_kata"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />
    <Button
        android:id="@+id/enkrip_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Enkrip"
        />
    <EditText
        android:id="@+id/teks_enkrip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />
</LinearLayout>

Ok, that's all for today, happy coding, and go Open Source.

Minggu, 16 September 2012

Integrasi Modul Enkripsi Pada VoIP Client berbasis Mobile


Abdi Wahab1, Rizal Bahaweres2 dan Mudrik Alaydrus3


Abstract – The use of VoIP in Indonesia industries is still very low, it’s caused by security problem that haven’t guarenteed by VoIP provider. For this security problem, VoIP users can only access the VoIP client, but not for the VoIP server build by VoIP provider. So, to secure the communication, users can secure the communication data transmitted via VoIP network, with adding encryption module into VoIP client. The growing use of smartphone also effect the increase of mobile application development, one of them is mobile VoIP client apps. This research try to integrate encryption module in VoIP client application especially for Android smartphone. Research methodology for this research use prototyping method for developing VoIP client integrated with encryption module. From the prototyping model, the module will be tested by communicated with the module. The results from the testing with black box method, obtained that the integrated encryption modul can run well to encrypt communication data.
Key Words: VoIP, VoIP Client, Encryption

Selasa, 04 September 2012

Aplikasi Enkripsi dan Dekripsi Menggunakan AES di Android

Kriptograpi pada salah satu buku dituliskan sebagai ilmu yang merahasiakan sebuah rahasia. Salah satu metode yang dapat digunakan untuk merahasiakan sebuah rahasia adalah enkripsi.
Untuk kali ini akan saya sharing sebuah aplikasi enkripsi dan dekripsi menggunakan Algoritma AES yang berjalan di Android. Untuk library yang saya gunakan pada aplikasi ini adalah JCE (Java Cryptography Extension). Tampilan dari aplikasi ini adalah sebagai berikut:

Untuk mulai membangun aplikasi ini, terlebih dahulu dibuat layout dari aplikasi. kode untuk menampilkan tampilan seperti di atas adalah sebagai berikut (ditulis di dalam main.xml yang berada di dalam direktory res/layout) :
 <?xml version="1.0" encoding="utf-8"?>  
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   android:orientation="vertical"  
   android:layout_width="fill_parent"  
   android:layout_height="fill_parent"  
   >  
 <TextView  
      android:id="@+id/teks_kunci"  
      android:layout_width="wrap_content"  
      android:layout_height="wrap_content"  
      android:text="Masukkan kunci"   
      />  
 <EditText  
      android:id="@+id/input_kunci"  
      android:layout_width="fill_parent"  
      android:layout_height="wrap_content"   
      />  
 <TextView  
      android:id="@+id/teks_kata"  
      android:layout_width="wrap_content"  
      android:layout_height="wrap_content"  
      android:text="Masukkan kata"   
      />  
 <EditText  
      android:id="@+id/input_kata"  
      android:layout_width="fill_parent"  
      android:layout_height="wrap_content"   
      />  
 <Button   
      android:id="@+id/enkrip_button"  
      android:layout_width="wrap_content"  
      android:layout_height="wrap_content"  
      android:text="Enkrip"  
      />  
 <EditText  
      android:id="@+id/teks_enkrip"  
      android:layout_width="fill_parent"  
      android:layout_height="wrap_content"   
      />  
 <Button   
      android:id="@+id/dekrip_button"  
      android:layout_width="wrap_content"  
      android:layout_height="wrap_content"  
      android:text="Dekrip"  
      />  
 <EditText  
      android:id="@+id/teks_dekrip"  
      android:layout_width="fill_parent"  
      android:layout_height="wrap_content"   
      />  
 </LinearLayout>  




Selanjutnya adalah Activity utama dari aplikasi. Untuk aplikasi ini saya beri nama AESAndroidActivity dan kelas activitynya adalah AESAndroidActivity.java. Isi dari kelas AESAndroidActivity.java adalah sebagai berikut:


package org.aes;

import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.*;
import android.view.View.*;

public class AESAndroidActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // set Instance
        final Button enkripButton = (Button)findViewById(R.id.enkrip_button);
        final Button dekripButton = (Button)findViewById(R.id.dekrip_button);
        final EditText inputKunci = (EditText)findViewById(R.id.input_kunci);
        final EditText inputKata = (EditText)findViewById(R.id.input_kata);
        final EditText teksEnkrip = (EditText)findViewById(R.id.teks_enkrip);
        final EditText teksDekrip = (EditText)findViewById(R.id.teks_dekrip);
        // handling for enkripButton
        enkripButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
        String ambilKunci = inputKunci.getText().toString();
        String ambilKata = inputKata.getText().toString();
        String enKata = "";
        try {
        enKata = GenerateAES.encrypt(ambilKunci, ambilKata);
        } catch (Exception e) {}
        teksEnkrip.setText(enKata);
        }
        });
        // handling for dekripButton
        dekripButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
        String ambilKunci = inputKunci.getText().toString();
        String ambilKata = teksEnkrip.getText().toString();
        String deKata = "";
        if(!ambilKata.equals(null)) {
            try {
            deKata = GenerateAES.decrypt(ambilKunci, ambilKata);
            } catch(Exception e) {
           
            }
            teksDekrip.setText(deKata);
        }
        }
        });
    }
}



Sedangkan kelas untuk menghasilkan algoritma AES pada aplikasi ini saya beri nama GenerateAES.java. Isi dari GenerateAES.java adalah sebagai berikut:


package org.aes;

import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.SecureRandom;

public class GenerateAES {
//private Cipher cipher;
//private SecretKeySpec sKey;
public GenerateAES() {
}

public static String encrypt(String seed, String cleartext) throws Exception {
        byte[] rawKey = getRawKey(seed.getBytes());
        byte[] result = encrypt(rawKey, cleartext.getBytes());
        return toHex(result);
}

public static String decrypt(String seed, String encrypted) throws Exception {
        byte[] rawKey = getRawKey(seed.getBytes());
        byte[] enc = toByte(encrypted);
        byte[] result = decrypt(rawKey, enc);
        return new String(result);
}

private static byte[] getRawKey(byte[] seed) throws Exception {
        KeyGenerator kgen = KeyGenerator.getInstance("AES");
        SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
        sr.setSeed(seed);
    kgen.init(128, sr); // 192 and 256 bits may not be available
    SecretKey skey = kgen.generateKey();
    byte[] raw = skey.getEncoded();
    return raw;
}


private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
    SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
        Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
    byte[] encrypted = cipher.doFinal(clear);
        return encrypted;
}

private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
    SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
        Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.DECRYPT_MODE, skeySpec);
    byte[] decrypted = cipher.doFinal(encrypted);
        return decrypted;
}

public static String toHex(String txt) {
        return toHex(txt.getBytes());
}

public static byte[] toByte(String hexString) {
        int len = hexString.length()/2;
        byte[] result = new byte[len];
        for (int i = 0; i < len; i++)
                result[i] = Integer.valueOf(hexString.substring(2*i, 2*i+2), 16).byteValue();
        return result;
}

public static String toHex(byte[] buf) {
        if (buf == null)
                return "";
        StringBuffer result = new StringBuffer(2*buf.length);
        for (int i = 0; i < buf.length; i++) {
                appendHex(result, buf[i]);
        }
        return result.toString();
}
private final static String HEX = "0123456789ABCDEF";
private static void appendHex(StringBuffer sb, byte b) {
        sb.append(HEX.charAt((b>>4)&0x0f)).append(HEX.charAt(b&0x0f));
}
}



Jika sudah jadi semua, tahap selanjutnya adalah melakukan kompilasi dan menjalankan aplikasi.
Happy coding. Salam open source.

Selasa, 12 Juni 2012

ANALISIS KINERJA VOIP CLIENT SIPDROID DENGAN MODUL ENKRIPSI TERINTEGRASI

Abdi Wahab1, Rizal Bahaweres2, Mudrik Alaydrus3 

Abstrak --
Jumlah pengguna VoIP di Indonesia masih kecil sekali, walaupun cost yang ditawarkan oleh VoIP lebih kecil dibandingkan dengan menggunakan telepon berpulsa. Salah satu alasannya adalah keamanan yang diberikan oleh penyedia layanan VoIP yang masih kurang. Pengguna VoIP belum mendapat layanan keamanan yang dapat menjamin keamanan komunikasi. Penelitian ini mencoba untuk mengamankan komunikasi antara pengguna VoIP dengan menggunakan modul enkripsi yang diintegrasikan dengan VoIP client Sipdroid yang berjalan di smartphone Android. Hal ini dimungkinkan oleh pengguna VoIP karena hanya VoIP client yang dapat diakses oleh pengguna VoIP. Hasil yang diperoleh setelah dilakukan integrasi dengan modul enkripsi menggunakan tiga buah skema enkripsi yaitu AES, DES, dan RC4, Sipdroid mampu menahan serangan pasif dari penyadapan informasi ( eavesdropping ) selama terjadi komunikasi. Dan hasil dari pengukuran QoS terdapat peningkatan delay sebesar 0.01 ms dan tidak terjadi perubahan yang signifikan terhadap througput dan packet loss, untuk throughput yang dihasilkan berkisar di 78 kbps, dan untuk packet loss rata-rata adalah 0.8 %. Akan tetapi terdapat noise yang mengikuti komunikasi pada Sipdroid yang terintegrasi dengan modul enkripsi akibat skew gelombang dari penambahan waktu proses ketika enkripsi. Kata Kunci: VoIP, VoIP client, Enkripsi

Insya'Allah paper ini akan dipresentasikan di SNATI 2012 pada tanggal 15-16 Juni 2012.