Created
February 11, 2023 02:31
-
-
Save AndroPlus-org/147c4527bdc36e6ff51854d2463a66cd to your computer and use it in GitHub Desktop.
oplus-telephony-common
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.oplus.internal.telephony.explock.util; | |
import android.text.TextUtils; | |
import java.security.MessageDigest; | |
import java.security.NoSuchAlgorithmException; | |
/* loaded from: classes.dex */ | |
public class ExpLockHelper { | |
private static int TYPE_REGIONNET_LOCK = 0; | |
public static boolean matchUnLock(String imei, String password, int type) { | |
String result = null; | |
if (type == TYPE_REGIONNET_LOCK) { | |
result = encryptRegionNetLockImei(imei); | |
} | |
if (imei == null || password == null || !password.equalsIgnoreCase(result)) { | |
return false; | |
} | |
return true; | |
} | |
private static String encryptRegionNetLockImei(String imei) { | |
byte[] salt = {94, -101, 103, 26, 52, 47, -120, 102}; | |
String result = newEncryptImeiBySalt(imei, salt); | |
return result; | |
} | |
private static String encryptImeiBySalt(String imei, byte[] salt) { | |
byte[] imeiByteArray = imei.getBytes(); | |
byte[] key = new byte[16]; | |
for (int i = 0; i < key.length; i++) { | |
switch (i) { | |
case 1: | |
key[i] = salt[0]; | |
break; | |
case 2: | |
case 4: | |
case 6: | |
case 8: | |
case 10: | |
case 12: | |
case 14: | |
default: | |
key[i] = imeiByteArray[i]; | |
break; | |
case 3: | |
key[i] = salt[1]; | |
break; | |
case 5: | |
key[i] = salt[2]; | |
break; | |
case 7: | |
key[i] = salt[3]; | |
break; | |
case 9: | |
key[i] = salt[4]; | |
break; | |
case 11: | |
key[i] = salt[5]; | |
break; | |
case 13: | |
key[i] = salt[6]; | |
break; | |
case 15: | |
key[i] = salt[7]; | |
break; | |
} | |
} | |
try { | |
MessageDigest md = MessageDigest.getInstance("SHA-256"); | |
md.update(key); | |
String result = bytes2Hex(md.digest()); | |
return result; | |
} catch (NoSuchAlgorithmException e) { | |
return null; | |
} catch (Exception e2) { | |
return null; | |
} | |
} | |
private static String newEncryptImeiBySalt(String imei, byte[] salt) { | |
byte[] imeiByteArray = imei.getBytes(); | |
int keyLength = imeiByteArray.length + salt.length; | |
byte[] key = new byte[keyLength]; | |
for (int i = 0; i < key.length; i++) { | |
if (i < imeiByteArray.length) { | |
key[i] = imeiByteArray[i]; | |
} else if (i >= imeiByteArray.length) { | |
key[i] = salt[i - imeiByteArray.length]; | |
} | |
} | |
try { | |
MessageDigest md = MessageDigest.getInstance("SHA-256"); | |
md.update(key); | |
String result = bytes2Hex(md.digest()); | |
return encryptSaltAgain(result); | |
} catch (NoSuchAlgorithmException e) { | |
return null; | |
} catch (Exception e2) { | |
return null; | |
} | |
} | |
private static String encryptSaltAgain(String salt) { | |
if (TextUtils.isEmpty(salt)) { | |
return null; | |
} | |
byte[] key = salt.getBytes(); | |
try { | |
MessageDigest md = MessageDigest.getInstance("SHA-256"); | |
md.update(key); | |
String result = bytes2Hex(md.digest()); | |
return result; | |
} catch (NoSuchAlgorithmException e) { | |
return null; | |
} catch (Exception e2) { | |
return null; | |
} | |
} | |
public static String bytes2Hex(byte[] inputbyte) { | |
String firstChar; | |
String hexResult = ""; | |
for (int i = 0; i < inputbyte.length; i++) { | |
String temp = Integer.toHexString(inputbyte[i] & 255); | |
if (temp.length() == 1) { | |
firstChar = "0"; | |
} else { | |
firstChar = temp.substring(0, 1); | |
} | |
if (i % 2 == 0) { | |
hexResult = hexResult + firstChar; | |
} | |
} | |
return hexResult; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment