如何读取Simcard序列号并将前16个号码用作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");
................我做错什么了??
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!)发布于 2017-01-18 19:26:18
好吧。现在我看到你的问题了。活动是从上下文继承的,所以当您在类getSystemService中调用MCrypt时,您确实希望调用super.getSystemService。
如果您希望在另一个类中有一个可用的上下文(如MCrypt),您可以将它作为参数传递给该类的一个方法(构造函数,您已经拥有),并保持对它的引用,等等。
将上下文参数添加到MCrypt中的构造函数中:
public class MCrypt {
Context mContext;
TelephonyManager mtelemamanger;
public MCrypt (Context context)//this is a constructor
{
mContext = context;
mtelemamanger = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
...将以下权限添加到Androidmanifest.xml文件中。
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>然后使用这个:
TelephonyManager telemamanger = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
String deviceid = telemamanger.getSimSerialNumber();getSimSerialNumber()函数返回一个字符串,其中包含提供程序、信息等。如果您想获得纯sim序列号,您必须得到最后14位数字。
String SecretKey = deviceid.substring(Math.max(0, deviceid.length() - 14));https://stackoverflow.com/questions/41703488
复制相似问题