Aqara Home v2.4.1版本的 MD5 值为:529779ac2bc0131db52a1fc3098d2b35
以下内容为反编译后的 c.java 源代码,内容仅作参考
package k.u.c.i.i3.r;
import android.os.Build;
import android.util.Log;
import androidx.annotation.RequiresApi;
import java.io.PrintStream;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.interfaces.ECPrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.util.Arrays;
import javax.crypto.KeyAgreement;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.asn1.sec.SECNamedCurves;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.InvalidCipherTextException;
import org.bouncycastle.crypto.engines.AESEngine;
import org.bouncycastle.crypto.generators.ECKeyPairGenerator;
import org.bouncycastle.crypto.modes.AEADBlockCipher;
import org.bouncycastle.crypto.modes.CCMBlockCipher;
import org.bouncycastle.crypto.params.AEADParameters;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.crypto.params.ECKeyGenerationParameters;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.jce.ECNamedCurveTable;
import org.bouncycastle.jce.interfaces.ECPublicKey;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
import org.bouncycastle.jce.spec.ECParameterSpec;
import org.bouncycastle.jce.spec.ECPrivateKeySpec;
import org.bouncycastle.jce.spec.ECPublicKeySpec;
import org.bouncycastle.util.encoders.Base64;
public class c {
public static final String a = "aqara-lock-ota-salt";
public static final int b = 4096;
public static final int c = 20;
public static String d = "0041044c4d4657034105312e302e34054104adacabad06230000000a07235d6a235d04230008b05a01203209410461b97800504c4a5401312e312e3900000000014fee548307240041044c4d465702200103410856312e312e393030054108323666623166383106230000004607235d69d8da082003042300014fee012043094108653463363863326400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a012002039960108f58f0108f78f010800000000000000000000000000000000000000000000000000000000f98f01080000000000000000fb8f0108fd8f0108abb2000873ce0008fb900108e7ec0008870b0108359001082b3d0108b190010800000000038301084f8501088785010897890108c7890108f38f010897950108079601080b9101081396010800000000159101085d9601085f960108619601086396010865960108679601081f9101087f910108699601080000000000000000bff34f8f034804490860bff34f8f00bffde700000400fa050ced00e0f8b5b748c178002905d10179002902d14079002805d0b3480088002801d106f069f8b1480088002813d1ae4c208800280fd1ae480078ae490978014309d1ad480088002805d006f0c1f806f0b1fb0a202080a94d0024287801280bd0a7480078012807d0a6480078012803d0a548007801280ed1c148018800290ad1048006f083fc200028709d4908709d4908709d4908700125ba48007801281fd1934e06f011fe002808d120003070b64e3078002814d12800307011e0307800280ed02146284606f0effd08f015f9200030708548048085480480200085490870b3480178002966d129000170b1480178002907d021000170284608f087fd3c2009f069f82800ac490870ac48008800281ad09c480078012816d10520a84908702000a84908702800a7490870a34804806d4804806d4804802800b5490870b549087009f0d1f8b5e09c48008800281ad0b1480078012816d10620994908702000ae490870280098490870944804805e4804805e4804802800a5490870a549087009f0b2f896e08d480088002800d091e08b4f574800787b490978014305d10320387028009e49087084e028003870fa209c4908807ee0744e307800282dd19a480188002912d099490a78012a0ed1984ad279002a0ad1974a527b042a06d0200008709548008807f091fe0fe073490c80048092480178012908d18e49c97a012904d1022101702800be490870280030703948048009f068f84ce0bb480178002925d166490988002921d1290001700320634908702000b549087096202e49088028007449087009f04ff8200029490870af4f387803282dd1200038707548407b06f00affab480480ab48048022e0c3480178002909d1290001700a20504908702146182006f01fff14e0bd480178002909d1290001700920494908702146be2006f011ff06e060480088002802d020000f490870b34e97480088002844d0944f3878002840d006f0c7fe002831d1387801281bd1ac488079012817d107f0ecff25e000bff41c0020961d0020981d0020061e0020fe1d00209a1d00202c1e0020291e00202e1e00202f1e00203878022802d107f0e5ff0ae03878032802d107f0dfff04e03878042801d107f0d9ff20007070b5480088142802da1420b249088028003449087008e07078002805d1280070703848407b06f08ffeac480088002834d0ab4f3878002830d006f075fe002813d138780a2809d107f09eff0be000bfe01d00207e0200206802002038780b2801d107f091ff200070709b480088142802da14209849088028001a49087016e067020020341e00208e0200209c1d0020f61d0020091e0020810200207078002805d1280070701748407b06f04dfe8d4f387800282cd18c480088002828d10e480088002824d161480078012820d187480078411e8941c943c90f014801701ae06d0200200c1e0020fb1d0020191e0020031e0020b01d00209e1d00206c020020601d0020641c0020881d0020f71d002028007749087070480088002804d075480078002800d0d3e06f480088002800d0cee071480088002800d0c9e06f480078012800d0c4e06e480078002800d0bfe06c48b178012903d1052101802100b1700088002800d0b6e006f04bfb002800d0b1e006f049fb002800d0ace006f047fb002800d0a7e006f045fb002800d0a2e05d480088002800d09de05c480088002800d098e05a480088002800d093e059480088002800d08ee057480088002800d089e006f0b1fd012810d10a2052490880f1bd00bf151e002065020020001e00201d1e0020dc1d0020c81d00203078012813d14a48007800280fd1280048490870484908702000307006f037fd20004649087046480480464804804648008800280fd14548008800280bd144480088002807d143480088002803d14248007800280cd00a2024490880f1bd00bf6f020020700200205a020020681d00200221a020c00509f013ff012815d1052008f01bfe0221a020c00509f009ff01280bd1204608f02cfb3c2008f00efe284608f026fb3c2008f008fe2c48007800281bd109f052ff002817d129480078002813d128480188094a1180008800280cd1280030700c490870bc48047007203870b570f1bd2800b0703570f1bd9a1d0020de1d00201e1e0020f61d00209c1d00207e0200206d0200200c1e00209e1d00201c1d0020351e0020a41d00208e1d0020921d0020901d0020941d0020c21d0020061e002080020020fe1d002073020020981d0020961d0020bc1d0020c41d0020c81d0020cc1d0020041e0020171e0020781d0020a21d002070b582b098480078002803d09748407b06f0f0fc684609f009f8002800d0f0e002216846008805f01ffa8e4e3070002421008f4a11808f4a1170012868d18e4d297801290bd08d490978012907d08c490978012903d08b490978012958d101216846008805f0e3ff2878012807d1022028700b208449087005f0e7fc41e07f480178012907d1022101700c207e49087005f0dbfc35e07a480178012916d102210a0002700d20784a1070784801701b2009f070fe962040007549088032307549088006f09cf805f0c0fc1ae06d480178012916d1022101700d206b49087003206a49087001461b2009f054fe962040006749088032306749088006f080f805f0a4fc0120644908700a206449088073bd012816d05849097801290bd057490978012907d056490978012903d055490978012906d105f08dff0221072009f02afe2ee0012811d14c4909784c4a12780a434b49097811434b4a12780a4305d121466846008805f063ff1ae0072813d12146042009f00ffe3220494908802000494908700146c22006f05cfc012008f0ecfc06f0bffb04e001216846008805f047ff02216846008804f0dbfc3178072916d0012911d03148304d2a78012a02d00278012a09d10322384b1a7022002a7002702000304a108002e00120334a107068460088324a10802000274a10703048072902d10721017001e0022101702d4804802ce001282ad1204d00242b48007801280fd1200028700120234908700220244908702648214908802248048005f0b7ff14e005f00eff20002870164908800e4908700e4908700e4908700e4804700221072009f09ffd022005f06efb08f002fd73bd0000fb1d00201d1e0020641c00208a1d0020fa1d0020291e00202c1e00202e1e00202f1e0020f61d0020301e0020e21d00209a1d0020680200209c1d0020a21d00200a1e0020f71d0020881d0020f91d0020b01d00207e020020ffff0000f8b5a5480078002803d0a448407b06f091fb0024a2480178002901d02100017068460af0a7f80125002800d0e1e09d4f29466846008805f0b7f8387020009a4908809a49087005f0bbf9387801286ed1974e317801290bd096490978012907d095490978012903d09449097801295ed129466846008805f07afe3078012807d1022030700b208e49087005f07efb44e088480178012907d1022101700c208849087005f072fb38e083490878012818d1022002000a702100824a11800d21804a11708149087001461b2009f003fd962040007e49088032307d49088005f055fb1be076480178012917d1022101702000744908800d207249087003207249087001461b2009f0e6fc962040006f49088032306f49088005f038fb09f07ffd9e4805706c4804700a206b490880f1bd012816d05f49097801290bd05e490978012907d05d490978012903d05c490978012906d105f01efe4021072009f0bbfc18e0012811d15248007852490978014352480078084351490978014305d121466846008805f0f4fd04e029466846008805f0eefd29466846008804f082fb3878012819d04448424e317801290ad00178012907d041490978012903d040490978012909d10321754a117021003170017020003f49088002e0280070490870684600886f49088020003649087028006d49087030e001282ed16c48007801280fd12800664908706749087083486549088005f066fe09f003fd20002e49087017e07f484078012801d105f0b4fd2000284908801f4908701f4908701f4908701f4908704021072009f046fc284605f015fa20001b490870504f1a4e387800280ad109f0c7fc2800387020001a49087030701848048004e028006a4908706a4804703078002805d12800684908701e206749088067480570f1bd00001d1e0020641c0020341e0020fb1d00208a1d0020fa1d0020291e00202c1e00202e1e00202f1e0020f61d0020e01d0020301e0020e21d00209a1d0020001e00209c1d002010b582b054480078002803d05348407b06f022fa68460af0d0fb00282ad103216846008804f052ff4d490870002421004c4a11804c4a1170012804d16846008805f027fd04e001216846008805f021fd03216846008804f0b5fa0120184908706846008817490880404804700320164908701fe001281dd100241448007801280bd101200e49087003200f4908702b480c49088005f0b5fd0ae005f00cfd200033490880642033490880032005f076f92e48047001202749087013bd68020020f71d0020881d0020f91d00207e02002029488079002800d1704710b5274c207800282ad126480078012809d11b48807a80070ad423480188234809f0f1fb04e020480188204803f0effc15480178012903d0032901d00221017001200100217000219b4a1180174a11809a4a9a4b1b78012b01d1107010bd117010bdffff0000f41c002067020020061e002065020020b01d0020730200201d1e0020641c0020fb1d00208a1d0020fa1d0020f61d00209a1d0020b21d0020601d00206e02002086020020d21d002008160020f8b583480078002804d0022802d0042855d0f3e07f480088002809d0012420007d4908707d48047000207d490870f1bd7c4d2878012810d1002405217a4808f0a3fc002803d105f023fc2c7005e005f0c9fc0120287070480470714f3878002800d1cee0002420003870704e3078032805db6f498979002901d1401c30703078012802d0022804d007e002206949087004e001206749087000e00124002c00d0afe007f059fa04200100594a117001242100614a11";
@RequiresApi(api = 19)
public static void a(String[] strArr) throws Exception {
KeyPair a2 = a();
c(a(((ECPublicKey) a2.getPublic()).getQ().a(true), ((ECPrivateKey) a2.getPrivate()).getS().toByteArray()));
byte[] a3 = a("8ffc5eb8a59500c6fe3e079067017b213b276b6ab6b38c39");
byte[] bArr = new byte[16];
System.arraycopy(a3, 0, bArr, 0, 16);
byte[] bArr2 = new byte[8];
System.arraycopy(a3, 16, bArr2, 0, 8);
System.out.println(a(b(bArr, bArr2, a(d))));
}
public static byte[] b(byte[] bArr, byte[] bArr2) {
if (Build.VERSION.SDK_INT < 19) {
return null;
}
byte[] bArr3 = new byte[8];
System.arraycopy(bArr2, 16, bArr3, 0, 8);
PrintStream printStream = System.out;
printStream.println("向量的内容: " + a(bArr3) + " length: 8");
StringBuilder sb = new StringBuilder();
sb.append(a(bArr3));
sb.append(" length: ");
sb.append(8);
Log.e("生成向量 ======> ", sb.toString());
return bArr3;
}
public static SecretKey c(byte[] bArr) {
if (Build.VERSION.SDK_INT < 19) {
return null;
}
g.a.a.a.a b2 = g.a.a.a.a.b();
SecretKeySpec secretKeySpec = new SecretKeySpec(b2.a(b2.a(a.getBytes(StandardCharsets.UTF_8), bArr), (byte[]) null, 24), "AES");
Log.e("AES KEY ======> ", a(secretKeySpec.getEncoded()) + " length: " + secretKeySpec.getEncoded().length);
PrintStream printStream = System.out;
printStream.println("AES KEY 长度: " + secretKeySpec.getEncoded().length + " 内容为:" + a(secretKeySpec.getEncoded()));
PrintStream printStream2 = System.out;
StringBuilder sb = new StringBuilder();
sb.append("AES KEY base64");
sb.append(Base64.c(secretKeySpec.getEncoded()));
printStream2.println(sb.toString());
return secretKeySpec;
}
public static ECPublicKey d(byte[] bArr) {
ECNamedCurveParameterSpec a2 = ECNamedCurveTable.a("secp256r1");
ECParameterSpec eCParameterSpec = new ECParameterSpec(a2.a(), a2.b(), a2.d(), a2.c(), a2.e());
try {
return (ECPublicKey) KeyFactory.getInstance("ECDH", new BouncyCastleProvider()).generatePublic(new ECPublicKeySpec(eCParameterSpec.a().a(bArr), eCParameterSpec));
} catch (NoSuchAlgorithmException e2) {
e2.printStackTrace();
return null;
} catch (InvalidKeySpecException e3) {
e3.printStackTrace();
return null;
}
}
public static byte[] b(byte[] bArr, byte[] bArr2, byte[] bArr3) {
AESEngine aESEngine = new AESEngine();
AEADParameters aEADParameters = new AEADParameters(new KeyParameter(bArr), 32, bArr2);
CCMBlockCipher cCMBlockCipher = new CCMBlockCipher(aESEngine);
cCMBlockCipher.a(true, (CipherParameters) aEADParameters);
return a(cCMBlockCipher, bArr3);
}
public static KeyPair b() {
KeyPair generateKeyPair;
KeyPair keyPair = null;
try {
X9ECParameters c2 = SECNamedCurves.c("secp256r1");
PrintStream printStream = System.out;
printStream.println("=====================》测试,X9生成ECDH公钥: " + a(c2.l().a(true)));
new ECParameterSpec(c2.i(), c2.l(), c2.n(), c2.m(), c2.o());
ECDomainParameters eCDomainParameters = new ECDomainParameters(c2.i(), c2.l(), c2.n(), c2.m(), c2.o());
ECNamedCurveParameterSpec a2 = ECNamedCurveTable.a("secp256r1");
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("EC", new BouncyCastleProvider());
keyPairGenerator.initialize(a2, new SecureRandom());
generateKeyPair = keyPairGenerator.generateKeyPair();
byte[] a3 = a2.b().a(true);
PrintStream printStream2 = System.out;
printStream2.println("=====================》测试,生成ECDH公钥key pair: " + a(((ECPublicKey) generateKeyPair.getPublic()).getQ().a(true)));
PrintStream printStream3 = System.out;
printStream3.println("=====================》测试,生成ECDH公钥: " + a(a3));
new ECKeyPairGenerator().a(new ECKeyGenerationParameters(eCDomainParameters, new SecureRandom()));
} catch (InvalidAlgorithmParameterException e2) {
e = e2;
} catch (NoSuchAlgorithmException e3) {
e = e3;
}
try {
PrintStream printStream4 = System.out;
printStream4.println("=====================》测试,生成EC公钥: " + a(((ECPublicKey) generateKeyPair.getPublic()).getQ().a(true)));
PrintStream printStream5 = System.out;
printStream5.println("=====================》测试,生成EC私钥: " + a(generateKeyPair.getPrivate().getEncoded()));
return generateKeyPair;
} catch (InvalidAlgorithmParameterException e4) {
e = e4;
keyPair = generateKeyPair;
e.printStackTrace();
return keyPair;
} catch (NoSuchAlgorithmException e5) {
e = e5;
keyPair = generateKeyPair;
e.printStackTrace();
return keyPair;
}
}
public byte[][] a(byte[] bArr, int i2) {
double parseDouble = Double.parseDouble(i2 + "");
int ceil = (int) Math.ceil(((double) bArr.length) / parseDouble);
byte[][] bArr2 = new byte[ceil];
for (int i3 = 0; i3 < ceil; i3++) {
int i4 = (int) (i3 * parseDouble);
int i5 = (int) (i4 + parseDouble);
if (i5 > bArr.length) {
i5 = bArr.length;
}
bArr2[i3] = Arrays.copyOfRange(bArr, i4, i5);
}
return bArr2;
}
public static KeyPair a() {
KeyPair keyPair = null;
try {
ECNamedCurveParameterSpec a2 = ECNamedCurveTable.a("secp256r1");
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("EC", new BouncyCastleProvider());
keyPairGenerator.initialize(a2, new SecureRandom());
keyPair = keyPairGenerator.generateKeyPair();
ECPublicKey eCPublicKey = (ECPublicKey) keyPair.getPublic();
org.bouncycastle.jce.interfaces.ECPrivateKey eCPrivateKey = (org.bouncycastle.jce.interfaces.ECPrivateKey) keyPair.getPrivate();
return keyPair;
} catch (InvalidAlgorithmParameterException e2) {
e2.printStackTrace();
return keyPair;
} catch (NoSuchAlgorithmException e3) {
e3.printStackTrace();
return keyPair;
}
}
public static byte[] a(byte[] bArr, int i2, int i3) {
int length = bArr.length / 4096;
int i4 = i2 * 4096;
if (i2 == 1) {
i4 = 0;
}
byte[] bArr2 = new byte[4096];
for (int i5 = i4; i5 < i4 + i4; i5++) {
if (i5 <= 4096) {
bArr2[i5] = bArr[i5];
}
}
return bArr2;
}
public static byte[] a(byte[] bArr, byte[] bArr2, byte[] bArr3) {
if (Build.VERSION.SDK_INT < 19) {
return null;
}
AESEngine aESEngine = new AESEngine();
AEADParameters aEADParameters = new AEADParameters(new KeyParameter(bArr), 32, bArr2);
CCMBlockCipher cCMBlockCipher = new CCMBlockCipher(aESEngine);
cCMBlockCipher.a(false, (CipherParameters) aEADParameters);
return a(cCMBlockCipher, bArr3);
}
public static short b(byte[] bArr) {
return ByteBuffer.wrap(bArr).order(ByteOrder.LITTLE_ENDIAN).getShort();
}
public static byte[] a(AEADBlockCipher aEADBlockCipher, byte[] bArr) {
int b2 = aEADBlockCipher.b(bArr.length);
byte[] bArr2 = new byte[b2];
int a2 = aEADBlockCipher.a(bArr, 0, bArr.length, bArr2, 0);
a(bArr);
try {
a2 += aEADBlockCipher.a(bArr2, a2);
} catch (InvalidCipherTextException e2) {
e2.printStackTrace();
}
if (a2 == b2) {
return bArr2;
}
byte[] bArr3 = new byte[a2];
System.arraycopy(bArr2, 0, bArr3, 0, a2);
return bArr3;
}
public static byte[] a(byte[] bArr, byte[] bArr2) {
ECNamedCurveParameterSpec a2 = ECNamedCurveTable.a("secp256r1");
ECParameterSpec eCParameterSpec = new ECParameterSpec(a2.a(), a2.b(), a2.d(), a2.c(), a2.e());
ECPrivateKeySpec eCPrivateKeySpec = new ECPrivateKeySpec(new BigInteger(1, bArr2), eCParameterSpec);
ECPublicKeySpec eCPublicKeySpec = new ECPublicKeySpec(eCParameterSpec.a().a(bArr), eCPrivateKeySpec.a());
byte[] bArr3 = null;
try {
KeyFactory keyFactory = KeyFactory.getInstance("ECDH", new BouncyCastleProvider());
PublicKey generatePublic = keyFactory.generatePublic(eCPublicKeySpec);
PrivateKey generatePrivate = keyFactory.generatePrivate(eCPrivateKeySpec);
KeyAgreement keyAgreement = KeyAgreement.getInstance("ECDH", new BouncyCastleProvider());
keyAgreement.init(generatePrivate);
keyAgreement.doPhase(generatePublic, true);
bArr3 = keyAgreement.generateSecret();
PrintStream printStream = System.out;
printStream.println("sharedKey :" + a(bArr3));
return bArr3;
} catch (InvalidKeyException e2) {
e2.printStackTrace();
return bArr3;
} catch (NoSuchAlgorithmException e3) {
e3.printStackTrace();
return bArr3;
} catch (InvalidKeySpecException e4) {
e4.printStackTrace();
return bArr3;
}
}
public static String a(byte[] bArr) {
StringBuffer stringBuffer = new StringBuffer();
for (int i2 = 0; i2 < bArr.length; i2++) {
int i3 = (bArr[i2] >>> 4) & 15;
int i4 = 0;
while (true) {
if (i3 >= 0 && i3 <= 9) {
stringBuffer.append((char) (i3 + 48));
} else {
stringBuffer.append((char) ((i3 - 10) + 97));
}
i3 = bArr[i2] & 15;
int i5 = i4 + 1;
if (i4 >= 1) {
break;
}
i4 = i5;
}
}
return stringBuffer.toString();
}
public static byte[] a(String str) {
int length = str.length();
byte[] bArr = new byte[length / 2];
for (int i2 = 0; i2 < length; i2 += 2) {
bArr[i2 / 2] = (byte) ((Character.digit(str.charAt(i2), 16) << 4) + Character.digit(str.charAt(i2 + 1), 16));
}
return bArr;
}
}