我想創建一個帶有RSA加密保護的短信應用程序。 我想問如何存儲公鑰?Android存儲RSA公鑰到文件夾
我試圖從Storing.class導入方法,但失敗了。
這是我的代碼
public class storePubKey extends BroadcastReceiver
{
Storing store = new Storing();
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
try{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str = msgs[i].getMessageBody().toString();
store.saveToFile("public.key",str);
}
}catch(Exception e){}
}
//---display the new SMS message---
try {
Toast.makeText(context,("public.keyYYYYYY"), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public class Storing extends Activity {
public void saveToFile(String filename, String sms) throws NoSuchAlgorithmException, InvalidKeySpecException, IOException{
OutputStreamWriter out = new OutputStreamWriter(openFileOutput(filename, Context.MODE_APPEND));
out.write(sms);
out.close();
}
你能告訴我如何將簡單字符串更改爲RSA格式...儘快回覆... –