How can I read the Simcard serial number and use the first 16 numbers as a SecretKey
........
private String SecretKey = "0123456789abcdef";**//Read the Simcard serial number and use the first 16 numbers as a SecretKey**
public MCrypt()
{
ivspec = new IvParameterSpec(iv.getBytes());
keyspec = new SecretKeySpec(SecretKey.getBytes(), "AES");
................
what I'm doing wrong ??
public class MCrypt {
static char[] HEX_CHARS = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
private String deviceid = telephonyManager.getSimSerialNumber();
//private String deviceid = "894310210159403811111456457657845786485458";
private String serial = new String (deviceid.substring(0, 16));
private String iv = ""+serial;//Dummy iv (CHANGE IT!) 8943102101594038
private static IvParameterSpec ivspec;
private static SecretKeySpec keyspec;
private static Cipher cipher;
private static Context context;
private String SecretKey = "0123456789abcdef";//Dummy secretKey (CHANGE IT!)
O.k. now I see your problem. Activity inherit's from Context - so when you are calling getSystemService in your class MCrypt , you are really wanting to call super.getSystemService.
If you want to have a Context available in another class (like MCrypt), you can pass it in as an argument to a method of that class (the constructor, which you already have), and keep a reference to it, etc.
Add Context argument to your constructor in MCrypt:
Add the below permission into your
Androidmanifest.xml
file.Then use this:
the getSimSerialNumber() function returns a string which contains provider info etc. If you want to get the pure sim serial number you have to get the last 14 digits.