开发者

Android Storing RSA Public Key to folder

开发者 https://www.devze.com 2023-03-27 03:16 出处:网络
I\'m trying to create a SMS Apps with RSA encryption protection. I would like to ask how can I store the PublicKey?

I'm trying to create a SMS Apps with RSA encryption protection. I would like to ask how can I store the PublicKey?

I tried to import methods from Storing.class, but failed.

th开发者_如何学运维is is my code

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();

}


Since you're asking about the public key specifically, I'll assume you're not asking how to secure it, and you're just asking about IO.

You have several options, detailed in the Data Storage section of the Android developer's guide. The 3 main ones for local storage are SQL database, SharedPreferences, and Files. If the question is more about how to store the user's public key on their own device, that would probably either be a file or a shared preference. However, since you're going to be storing multiple public keys (the ones of everyone you're communicating with, in order to decrypt their messages), I'd recommend going the SQL database route.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号