A few weeks a go, exactly on December 10 until December 12, I went to Lombok to testing VMS application I've developed. One of my task is testing and trying the VMS apps for real testing on board or vessel. This project is from IMACS USAID, because they want give this application to DKP Lombok for monitoring vessel under 30 GT. Because there's no regulation for monitoring vessel under 30 GT.
It was very interesting experience, because that the first time I land my feet on NTB, and the first time testing real GPS devices on vessel board. May be I'll tell a lot about application in the next post. And here is the boat I used to try the apps and GPS.
Hee... May be in January, I'll go back to Lombok to present elogbook apps.
Senin, 23 Desember 2013
Minggu, 14 April 2013
Car Rental Application with SMS Gateway
Ok, in this post I'll show my project with my friend, Hendri, for building a car rental
application with sms gateway integrated. In this application, user can reserve a car via sms, but the user must be registered first at office.
This is the screen shoot of application.
That's the first screen of application. I'll complete it later. If you interest with this app, don't hesitate to contact me.
application with sms gateway integrated. In this application, user can reserve a car via sms, but the user must be registered first at office.
This is the screen shoot of application.
That's the first screen of application. I'll complete it later. If you interest with this app, don't hesitate to contact me.
Label:
Car Rental,
Java,
Open Source,
Research,
SMS Gateway
Senin, 05 November 2012
Simple Temperature Conversion Apps for Android (Aplikasi Konversi Suhu Sederhana untuk Android)
Ok, in this post, I'll post a simple apps for conversion of temperature. This apps for only Android phone. And this is the capture of the application.
In this apps, I use spinner to add dropdown box like in a website. Ok, to make this app, so these are the codes you need to write.
First of all is main activity layout, I named it activity_conversion.xml. It's look like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="14dp"
android:text="@string/hello_world"
tools:context=".ConversionActivity" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="16dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner1"
android:layout_below="@+id/spinner1"
android:layout_marginTop="20dp"
android:text="@string/hello2" />
<Spinner
android:id="@+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="22dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner2"
android:layout_below="@+id/spinner2"
android:layout_marginTop="14dp"
android:text="@string/insert_temp" />
<EditText
android:id="@+id/insert_editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:layout_marginTop="20dp"
android:ems="10" />
<Button
android:id="@+id/convert_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/insert_editText"
android:layout_below="@+id/insert_editText"
android:text="@string/convert_button" />
<EditText
android:id="@+id/result_editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/convert_button"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/result_editText"
android:layout_alignLeft="@+id/result_editText"
android:layout_marginBottom="22dp"
android:text="@string/result" />
</RelativeLayout>
And for the second is strings.xml. Here it's the code for strings.xml:
<resources>
<string name="app_name">TempConversion</string>
<string name="hello_world">Choose your temperature from</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_conversion">ConversionActivity</string>
<string name="hello2">Conversion to</string>
<string name="insert_temp">Insert your temperature</string>
<string name="result">The result is</string>
<string name="convert_button">Convert</string>
<string-array name="nama_suhu">
<item>Celcius</item>
<item>Fahrenheit</item>
<item>Kelvin</item>
<item>Reamur</item>
</string-array>
<string-array name="nama_suhu2">
<item>Celcius</item>
<item>Fahrenheit</item>
<item>Kelvin</item>
<item>Reamur</item>
</string-array>
</resources>
Next is the main activity, I named it with ConversionActivity.java. And the codes are:
package org.tempconversion;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
public class ConversionActivity extends Activity implements OnItemSelectedListener{
//private String suhu1, suhu2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_conversion);
final Spinner pilTemp1 = (Spinner)findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.nama_suhu, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
pilTemp1.setAdapter(adapter);
final Spinner pilTemp2 = (Spinner)findViewById(R.id.spinner2);
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this, R.array.nama_suhu2, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
pilTemp2.setAdapter(adapter2);
final EditText inputTemp = (EditText)findViewById(R.id.insert_editText);
final EditText resultTemp = (EditText)findViewById(R.id.result_editText);
final Button convertButton = (Button)findViewById(R.id.convert_button);
// event for button
convertButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String suhu1 = pilTemp1.getSelectedItem().toString();
String suhu2 = pilTemp2.getSelectedItem().toString();
String strSuhu = inputTemp.getText().toString();
String strSuhuAkhir = "";
double suhuAwal = Double.parseDouble(strSuhu);
double suhuResult = 0;
// selection for converting suhu
// start with Celcius first
if(suhu1.equals("Celcius")) {
if(suhu2.equals("Fahrenheit")) {
suhuResult = (suhuAwal * 9 / 5) + 32;
} else if(suhu2.equals("Kelvin")) {
suhuResult = suhuAwal + 273;
} else if(suhu2.equals("Reamur")) {
suhuResult = suhuAwal * 4 / 5;
} else {
suhuResult = suhuAwal;
}
} else if(suhu1.equals("Fahrenheit")) {
if(suhu2.equals("Celcius")) {
suhuResult = (suhuAwal - 32) * 5 / 9;
} else if(suhu2.equals("Kelvin")) {
suhuResult = (suhuAwal - 459) * 5 / 9;
} else if(suhu2.equals("Reamur")) {
suhuResult = (suhuAwal - 32) * 4 / 9;
} else {
suhuResult = suhuAwal;
}
} else if(suhu1.equals("Kelvin")) {
if(suhu2.equals("Celcius")) {
suhuResult = suhuAwal - 273;
} else if(suhu2.equals("Fahrenheit")) {
suhuResult = suhuAwal * 9 / 5 - 459;
} else if(suhu2.equals("Reamur")) {
suhuResult = (suhuAwal - 273) * 4 / 5;
} else {
suhuResult = suhuAwal;
}
} else if(suhu1.equals("Reamur")) {
if(suhu2.equals("Celcius")) {
suhuResult = suhuAwal * 5 / 4;
} else if(suhu2.equals("Kelvin")) {
suhuResult = suhuAwal * 5 / 4 + 273;
} else if(suhu2.equals("Fahrenheit")) {
suhuResult = suhuAwal * 9 / 4 + 32;
} else {
suhuResult = suhuAwal;
}
}
strSuhuAkhir = Double.toString(suhuResult);
resultTemp.setText(strSuhuAkhir);
}
});
}
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// An item was selected. You can retrieve the selected item using
// parent.getItemAtPosition(pos)
}
public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_conversion, menu);
return true;
}
}
Ok, that's all for sharing today. Happy coding and go open source.
In this apps, I use spinner to add dropdown box like in a website. Ok, to make this app, so these are the codes you need to write.
First of all is main activity layout, I named it activity_conversion.xml. It's look like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="14dp"
android:text="@string/hello_world"
tools:context=".ConversionActivity" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="16dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner1"
android:layout_below="@+id/spinner1"
android:layout_marginTop="20dp"
android:text="@string/hello2" />
<Spinner
android:id="@+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="22dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner2"
android:layout_below="@+id/spinner2"
android:layout_marginTop="14dp"
android:text="@string/insert_temp" />
<EditText
android:id="@+id/insert_editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:layout_marginTop="20dp"
android:ems="10" />
<Button
android:id="@+id/convert_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/insert_editText"
android:layout_below="@+id/insert_editText"
android:text="@string/convert_button" />
<EditText
android:id="@+id/result_editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/convert_button"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/result_editText"
android:layout_alignLeft="@+id/result_editText"
android:layout_marginBottom="22dp"
android:text="@string/result" />
</RelativeLayout>
And for the second is strings.xml. Here it's the code for strings.xml:
<resources>
<string name="app_name">TempConversion</string>
<string name="hello_world">Choose your temperature from</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_conversion">ConversionActivity</string>
<string name="hello2">Conversion to</string>
<string name="insert_temp">Insert your temperature</string>
<string name="result">The result is</string>
<string name="convert_button">Convert</string>
<string-array name="nama_suhu">
<item>Celcius</item>
<item>Fahrenheit</item>
<item>Kelvin</item>
<item>Reamur</item>
</string-array>
<string-array name="nama_suhu2">
<item>Celcius</item>
<item>Fahrenheit</item>
<item>Kelvin</item>
<item>Reamur</item>
</string-array>
</resources>
Next is the main activity, I named it with ConversionActivity.java. And the codes are:
package org.tempconversion;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
public class ConversionActivity extends Activity implements OnItemSelectedListener{
//private String suhu1, suhu2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_conversion);
final Spinner pilTemp1 = (Spinner)findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.nama_suhu, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
pilTemp1.setAdapter(adapter);
final Spinner pilTemp2 = (Spinner)findViewById(R.id.spinner2);
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this, R.array.nama_suhu2, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
pilTemp2.setAdapter(adapter2);
final EditText inputTemp = (EditText)findViewById(R.id.insert_editText);
final EditText resultTemp = (EditText)findViewById(R.id.result_editText);
final Button convertButton = (Button)findViewById(R.id.convert_button);
// event for button
convertButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String suhu1 = pilTemp1.getSelectedItem().toString();
String suhu2 = pilTemp2.getSelectedItem().toString();
String strSuhu = inputTemp.getText().toString();
String strSuhuAkhir = "";
double suhuAwal = Double.parseDouble(strSuhu);
double suhuResult = 0;
// selection for converting suhu
// start with Celcius first
if(suhu1.equals("Celcius")) {
if(suhu2.equals("Fahrenheit")) {
suhuResult = (suhuAwal * 9 / 5) + 32;
} else if(suhu2.equals("Kelvin")) {
suhuResult = suhuAwal + 273;
} else if(suhu2.equals("Reamur")) {
suhuResult = suhuAwal * 4 / 5;
} else {
suhuResult = suhuAwal;
}
} else if(suhu1.equals("Fahrenheit")) {
if(suhu2.equals("Celcius")) {
suhuResult = (suhuAwal - 32) * 5 / 9;
} else if(suhu2.equals("Kelvin")) {
suhuResult = (suhuAwal - 459) * 5 / 9;
} else if(suhu2.equals("Reamur")) {
suhuResult = (suhuAwal - 32) * 4 / 9;
} else {
suhuResult = suhuAwal;
}
} else if(suhu1.equals("Kelvin")) {
if(suhu2.equals("Celcius")) {
suhuResult = suhuAwal - 273;
} else if(suhu2.equals("Fahrenheit")) {
suhuResult = suhuAwal * 9 / 5 - 459;
} else if(suhu2.equals("Reamur")) {
suhuResult = (suhuAwal - 273) * 4 / 5;
} else {
suhuResult = suhuAwal;
}
} else if(suhu1.equals("Reamur")) {
if(suhu2.equals("Celcius")) {
suhuResult = suhuAwal * 5 / 4;
} else if(suhu2.equals("Kelvin")) {
suhuResult = suhuAwal * 5 / 4 + 273;
} else if(suhu2.equals("Fahrenheit")) {
suhuResult = suhuAwal * 9 / 4 + 32;
} else {
suhuResult = suhuAwal;
}
}
strSuhuAkhir = Double.toString(suhuResult);
resultTemp.setText(strSuhuAkhir);
}
});
}
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// An item was selected. You can retrieve the selected item using
// parent.getItemAtPosition(pos)
}
public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_conversion, menu);
return true;
}
}
Ok, that's all for sharing today. Happy coding and go open source.
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.
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.
Label:
Android,
Java,
Mobile Application,
Open Source,
Security
Selasa, 02 Oktober 2012
Using pointer to initialize Array 2D ( Menggunakan Pointer untuk menginisialisasi Array 2D)
Ok, in this post, I would like to share about pointer in c. Even this pointer an old stuff, but, if you are interest in kernel and embedded system, it always use. Go to the topics, I'll share a little c code to initialize a 2D array with a pointer. The pointer will be a parameter in a function. This is the code:
#include <stdio.h>
void main(){
int a[2][2];
int b[2][2];
int i,j;
initArray(a,2,2);
//display(a,2,2);
//show(b,2,2);
//show(a,2,2);
for(i=0;i<2;i++) {
for(j=0;j<2;j++) {
printf("a[%d][%d]: %d ",i,j,a[i][j]);
}
printf("\n");
}
}
void initArray(int *k, int r, int c) {
int i,j,*z;
for(i=0;i<r;i++) {
z = k+i*r;
for(j=0;j<c;j++) {
printf("arr[%d][%d]: ",i,j);
scanf("%d", &(*(z+j)));
}
}
}
display(int *k,int r,int c){
int i,j,*z;
printf("Display\n");
for(i=0;i<r;i++){
z=k+i*r;
printf("%p \n",z);
for(j=0;j<c;j++){
printf("%d, %p\n",*(z+j), &(*(z+j)));
}
}
}
show(int *q,int ro,int co){
int i,j;
printf("Show");
for(i=0;i<ro;i++){
printf("\n");
for(j=0;j<co;j++){
printf("%d",*(q+i*co+j));
}
}
}
And this is the capture of the running program.
Go Open Source... and Happy Coding.
#include <stdio.h>
void main(){
int a[2][2];
int b[2][2];
int i,j;
initArray(a,2,2);
//display(a,2,2);
//show(b,2,2);
//show(a,2,2);
for(i=0;i<2;i++) {
for(j=0;j<2;j++) {
printf("a[%d][%d]: %d ",i,j,a[i][j]);
}
printf("\n");
}
}
void initArray(int *k, int r, int c) {
int i,j,*z;
for(i=0;i<r;i++) {
z = k+i*r;
for(j=0;j<c;j++) {
printf("arr[%d][%d]: ",i,j);
scanf("%d", &(*(z+j)));
}
}
}
display(int *k,int r,int c){
int i,j,*z;
printf("Display\n");
for(i=0;i<r;i++){
z=k+i*r;
printf("%p \n",z);
for(j=0;j<c;j++){
printf("%d, %p\n",*(z+j), &(*(z+j)));
}
}
}
show(int *q,int ro,int co){
int i,j;
printf("Show");
for(i=0;i<ro;i++){
printf("\n");
for(j=0;j<co;j++){
printf("%d",*(q+i*co+j));
}
}
}
And this is the capture of the running program.
Go Open Source... and Happy Coding.
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, 11 September 2012
Initialize Array From Procedure in C
Sometimes, a very complicated algorithm use a lot of matrix, and I sometimes find a process to initialize a matrix or array from a procedure or function. So, this is a little example how to initialize array from procedure.
#include <stdio.h>
int main() {
// declare array a
int a[5];
int masukan;
printf("Masukkan nilai: ");
scanf("%d",&masukan);
// initialize array with method
test(a, masukan);
int j;
for(j = 0; j < 5; j++) {
printf("a[%d]: %d \n",j,a[j]);
}
return 0;
}
void test(int *b, int c) {
int i;
for(i = 0; i < 5; i++) {
b[i] = c;
}
}
FYI, I build this code in linux, and compile it with gcc. Just a little share today, I hope it can usefull. happy coding, go Open Source.
#include <stdio.h>
int main() {
// declare array a
int a[5];
int masukan;
printf("Masukkan nilai: ");
scanf("%d",&masukan);
// initialize array with method
test(a, masukan);
int j;
for(j = 0; j < 5; j++) {
printf("a[%d]: %d \n",j,a[j]);
}
return 0;
}
void test(int *b, int c) {
int i;
for(i = 0; i < 5; i++) {
b[i] = c;
}
}
FYI, I build this code in linux, and compile it with gcc. Just a little share today, I hope it can usefull. happy coding, go Open Source.
Langganan:
Postingan (Atom)





