android eclipse加密,Elliptic Curve Cryptography:在eclipse android中使用NFC发送加密消息

我目前正在研究一个ECC项目。 所以项目是这样的,我想从我的Android手机使用NFC向非接触式智能卡发送加密消息。 标签由不同的团队开发,所以这不是问题所在。

我已经在eclipse上创建了一个程序来发送和接收消息,但我想要对消息进行加密。

问题是,我对android eclipse很新,但我已经阅读了关于Android开发人员的描述以及在这个论坛上与ECC相关的所有问题,包括Nelenkov的博客 ,但我仍然找不到发送方式和使用NFC接收加密的消息。 有人可以帮帮我吗?

如果它有帮助,这是我写的使用NFC发送消息的代码:@SuppressLint({ "ParserError", "ParserError" })

public class Daftar extends Activity {

private NfcAdapter adapter;

private PendingIntent pendingIntent;

private IntentFilter writeTagFilters[];

boolean writeMode;

private Tag mytag;

Context ctx;

private EditText edNIM, edNama;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_daftar);

edNIM = (EditText) findViewById(R.id.editText1);

edNama = (EditText) findViewById(R.id.editText2);

Button Write = (Button) findViewById(R.id.button1);

crypto = Crypto.getInstance();

Write.setOnClickListener(new View.OnClickListener()

{

@Override

public void onClick(View v) {

try {

if(mytag==null){

Toast.makeText(getApplicationContext(), "Tag not found", Toast.LENGTH_LONG ).show();

}else{

String id = null;

String nama = null;

if(edNIM.getText()!=null && edNama.getText()!=null)

{

id = edNIM.getText().toString();

nama = edNama.getText().toString();

}

write(id+"?"+nama,mytag);

Toast.makeText(getApplicationContext(), "Data Pengguna Baru" +

"\nNIM = " + id +

"\nNama = " + nama

, Toast.LENGTH_LONG).show();

Intent Home = new Intent (getApplicationContext(), Home.class);

Home.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Home.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(Home);

}

} catch (IOException e) {

Toast.makeText(getApplicationContext(), "Penulisan Tag Mengalami Error", Toast.LENGTH_LONG ).show();

e.printStackTrace();

} catch (FormatException e) {

Toast.makeText(getApplicationContext(), "Penulisan Tag Mengalami Error" , Toast.LENGTH_LONG ).show();

e.printStackTrace();

}

}

});

adapter = NfcAdapter.getDefaultAdapter(this);

pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);

tagDetected.addCategory(Intent.CATEGORY_DEFAULT);

writeTagFilters = new IntentFilter[] { tagDetected };

}

private void write(String text, Tag tag) throws IOException, FormatException {

NdefRecord[] records = { createRecord(text) };

NdefMessage  message = new NdefMessage(records);

// Get an instance of Ndef for the tag.

Ndef ndef = Ndef.get(tag);

// Enable I/O

ndef.connect();

// Write the message

ndef.writeNdefMessage(message);

// Close the connection

ndef.close();

}

private NdefRecord createRecord(String text) throws UnsupportedEncodingException {

byte[] textBytes  = text.getBytes();

int    textLength = textBytes.length;

byte[] payload    = new byte[1 + textLength];

payload[0] = 0x01;

System.arraycopy(textBytes, 0, payload, 1 , textLength);

NdefRecord recordNFC = new NdefRecord(NdefRecord.TNF_MIME_MEDIA ,

"app/bikebdg".getBytes(Charset.forName("US-ASCII")),

new byte[0], payload);

return recordNFC;

}

public void save(View view) {

// Do something in response to button

Intent intent = new Intent(this, Home.class);

startActivity(intent);

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.daftar, menu);

return true;

}

@Override

protected void onNewIntent(Intent intent){

if(NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())){

mytag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

Toast.makeText(getApplicationContext(), "Kartu dapat ditulis" +

"\nTekan Save untuk menulis kartu", Toast.LENGTH_SHORT).show();

}}

@Override

public void onPause(){

super.onPause();

WriteModeOff();

}

@Override

public void onResume(){

super.onResume();

WriteModeOn();

}

private void WriteModeOn(){

writeMode = true;

adapter.enableForegroundDispatch(this, pendingIntent, writeTagFilters, null);

}

private void WriteModeOff(){

writeMode = false;

adapter.disableForegroundDispatch(this);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值