2
我是臺灣的學生。我正在學習如何在Android中進行編程。 但我有一個關於使用Spongy Castle庫在ECDH中生成密鑰對的問題。 當我啓動應用程序時,android系統顯示應用程序已停止。使用Spongy Castle圖書館在ECDH中生成密鑰對
這裏是我的代碼和我的進口
public class MainActivity<ECParams> extends Activity {
String msg,Test;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button generator= (Button) findViewById(R.id.key_pair_generator);
generator.setOnClickListener(ECkeyPairGenerator);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private Button.OnClickListener ECkeyPairGenerator = new Button.OnClickListener()
{
public void onClick(View v) {
KeyPairGenerator kpg=null;
ECGenParameterSpec ecParamSpec = new ECGenParameterSpec("secp224k1");
try {
kpg = KeyPairGeneratorSpi.getInstance("ECDH", "SC");
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchProviderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
kpg.initialize(ecParamSpec);
} catch (InvalidAlgorithmParameterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
KeyPair kpair=kpg.generateKeyPair();
msg="pp";
ShowMsg();
}
};
public static String byteArrayToHexString(byte b[]) {
StringBuffer s = new StringBuffer();
int LEN = b.length;
if (b.length != LEN)
throw new RuntimeException("byteArrayToHexString() " +
"wrong argument length (!="+LEN);
for (int j = 0; j < b.length; j++) {
s.append(Integer.toHexString((int)((b[j]>>4)&0x0f)));
s.append(Integer.toHexString((int)(b[j]&0x0f)));
}
return new String(s);
}
public void ShowMsg(){
Intent intent = new Intent();
intent.setClass(MainActivity.this, Show.class);
Bundle bundle = new Bundle();
bundle.putString("Show", msg);
intent.putExtras(bundle);
startActivity(intent);
}
}
請幫助。
安置自己的錯誤。 – wangyif2 2013-04-21 22:29:23