[英]Android Storing RSA Public Key to folder
我正在尝试创建具有RSA加密保护的SMS应用程序。 我想问一下如何存储公钥?
我试图从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();
}
由于您是专门询问公用密钥的,因此我假设您不是在询问如何保护公用密钥,而只是在询问IO。
您有几个选项,在Android开发人员指南的“ 数据存储”部分中有详细介绍。 用于本地存储的3个主要参数是SQL数据库,SharedPreferences和Files。 如果问题更多是关于如何在用户自己的设备上存储用户的公共密钥,则可能是文件或共享首选项。 但是,由于您将要存储多个公共密钥(与您通信的所有人,以便解密其消息),因此建议您使用SQL数据库路由。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.