현재 ECC 프로젝트를 진행 중입니다. 따라서 프로젝트가 이렇게 진행되면 NFC를 사용하여 안드로이드 폰에서 비접촉식 스마트 카드로 암호화 된 메시지를 보내려고합니다. 태그가 다른 팀에서 개발 중이므로 여기서 문제가되지 않습니다.Elliptic Curve Cryptography : eclipse android에서 NFC를 사용하여 암호화 된 메시지 보내기
나는 이클립스에서 이미 메시지를주고받는 프로그램을 만들었지 만 메시지를 암호화하고 싶습니다.
문제는 안드로이드 이클립스에 상당히 익숙하지만 이미 안드로이드 개발자들에 관한 설명을 읽었으며 Nelenkov's blog을 포함한이 포럼에서 ECC와 관련된 모든 문제를 읽었지만 여전히 길을 찾을 수 없습니다. 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);
}
}
그래서 암호화 된 콘텐츠가 포함 된 NDEF 메시지를 작성 하시겠습니까? – ThomasRS
네, 맞습니다. 저를 도와주세요? – RedCrimson
내 라이브러리에서 몇 가지 예제를 시도해보십시오. https://code.google.com/p/ndef-tools-for-android/ – ThomasRS