0

I can send a sms in my android app via this code

 SmsManager sm = SmsManager.getDefault();
 sm.sendTextMessage(edt_phoneNo, null, message, null, null);

but can I send a password protected sms? Have android a inteface to get password from user to open my sms?

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
Fatemeh
  • 177
  • 15
  • You can listen for new text messages in the inbox and open the one required to fetch the details. Then follow the encryption/decryption process as mentioned by @Andriy Omelchenko – Mohammed Atif Nov 15 '16 at 11:02

1 Answers1

1

You can just encrypt text of message by many ways. For example like in this answer

DESKeySpec keySpec = new DESKeySpec("Your secret Key phrase".getBytes("UTF8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(keySpec);
sun.misc.BASE64Encoder base64encoder = new BASE64Encoder();
sun.misc.BASE64Decoder base64decoder = new BASE64Decoder();
.........

// ENCODE plainTextPassword String
byte[] cleartext = plainTextPassword.getBytes("UTF8");      

Cipher cipher = Cipher.getInstance("DES"); // cipher is not thread safe
cipher.init(Cipher.ENCRYPT_MODE, key);
String encryptedPwd = base64encoder.encode(cipher.doFinal(cleartext));
// now you can store it 
......

// DECODE encryptedPwd String
byte[] encrypedPwdBytes = base64decoder.decodeBuffer(encryptedPwd);

Cipher cipher = Cipher.getInstance("DES");// cipher is not thread safe
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] plainTextPwdBytes = (cipher.doFinal(encrypedPwdBytes));
Community
  • 1
  • 1
Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
  • OkThank you very much.,but When I send a sms,the user get it in his inbox phone. I want the user open sms in his inbox. is it possible? I don't want user open it in android app. I want to open it in his sim card. – Fatemeh Nov 15 '16 at 11:00
  • Open is possible, but user will see encrypted text (may be even symbols, not only a..z letters). To decode encrypted text user needs your app. – Andrii Omelchenko Nov 15 '16 at 11:03
  • I think if user input password for decryption a lot of malware are exists and can stole password so I don't want to transfer password in android app.how can I do to keep secure password? – Fatemeh Nov 15 '16 at 11:06
  • I want to get password from user in secure way.how can I do it? – Fatemeh Nov 15 '16 at 11:09
  • For beginning read [this](https://en.wikipedia.org/wiki/Public-key_cryptography). It's complex topic which not be discussed in comments. – Andrii Omelchenko Nov 15 '16 at 12:11
  • I make a new topic in http://stackoverflow.com/questions/40609753/get-password-in-secure-way-in-android-app.please help me – Fatemeh Nov 15 '16 at 12:22