package oicq.wlogin_sdk.tools;
import
android.content.Context;
import
android.os.Build.VERSION;
import
java.security.Key;
import
java.security.KeyFactory;
import
java.security.KeyPair;
import
java.security.KeyPairGenerator;
import
java.security.PrivateKey;
import
java.security.PublicKey;
import
java.security.spec.AlgorithmParameterSpec;
import
java.security.spec.ECGenParameterSpec;
import
java.security.spec.X509EncodedKeySpec;
import
javax.crypto.KeyAgreement;
import
oicq.wlogin_sdk.report.Reporter;
import
oicq.wlogin_sdk.request.t;
public
class
EcdhCrypt
{
public static final String DEFAULT_PUB_KEY
=
"020b03cf3d99541f29ffec281bebbd4ea211292ac1f53d7128"
;
public static final String DEFAULT_SHARE_KEY
=
"4da0f614fc9f29c2054c77048a6566d7"
;
public static final String S_PUB_KEY
=
"04928D8850673088B343264E0C6BACB8496D697799F37211DEB25BB73906CB089FEA9639B4E0260498B51A992D50813DA8"
;
public static final String X509_S_PUB_KEY
=
"3046301006072A8648CE3D020106052B8104001F03320004928D8850673088B343264E0C6BACB8496D697799F37211DEB25BB73906CB089FEA9639B4E0260498B51A992D50813DA8"
;
public static byte[] _c_pri_key
=
new byte[
0
];
public static byte[] _c_pub_key
=
new byte[
0
];
private static byte[] _g_share_key
=
new byte[
0
];
private static boolean initFlg
=
false;
public static PrivateKey pkcs8PrivateKey;
private static boolean userOpenSSLLib
=
true;
public static PublicKey x509PublicKey;
public EcdhCrypt(Context paramContext)
{
util.loadLibrary(
"wtecdh"
, paramContext);
}
private byte[] calShareKeyByBouncycastle(byte[] paramArrayOfByte)
{
Object
localObject1
=
"3046301006072A8648CE3D020106052B8104001F03320004"
;
try
{
if
(paramArrayOfByte.length <
30
) {
localObject1
=
"302E301006072A8648CE3D020106052B8104001F031A00"
;
}
Object
localObject2
=
util.buf_to_string(paramArrayOfByte);
StringBuilder localStringBuilder
=
new java
/
lang
/
StringBuilder;
localStringBuilder.<init>();
localStringBuilder.append((String)localObject1);
localStringBuilder.append((String)localObject2);
localObject1
=
constructX509PublicKey(localStringBuilder.toString());
localObject2
=
new java
/
lang
/
StringBuilder;
((StringBuilder)localObject2).<init>();
((StringBuilder)localObject2).append(
"raw public key "
);
((StringBuilder)localObject2).append(util.buf_to_string(_c_pub_key));
util.LOGI(((StringBuilder)localObject2).toString(), "");
localObject2
=
new java
/
lang
/
StringBuilder;
((StringBuilder)localObject2).<init>();
((StringBuilder)localObject2).append(
"pkcs8PrivateKey "
);
((StringBuilder)localObject2).append(pkcs8PrivateKey.toString());
util.LOGI(((StringBuilder)localObject2).toString(), "");
localObject2
=
KeyAgreement.getInstance(
"ECDH"
,
"BC"
);
((KeyAgreement)localObject2).init(pkcs8PrivateKey);
((KeyAgreement)localObject2).doPhase((Key)localObject1, true);
localObject2
=
((KeyAgreement)localObject2).generateSecret();
localObject1
=
MD5.toMD5Byte((byte[])localObject2);
localStringBuilder
=
new java
/
lang
/
StringBuilder;
localStringBuilder.<init>();
localStringBuilder.append(
"share key "
);
localStringBuilder.append(util.buf_to_string((byte[])localObject2));
util.LOGI(localStringBuilder.toString(), "");
localObject2
=
new java
/
lang
/
StringBuilder;
((StringBuilder)localObject2).<init>();
((StringBuilder)localObject2).append(
"share key md5 "
);
((StringBuilder)localObject2).append(util.buf_to_string((byte[])localObject1));
util.LOGI(((StringBuilder)localObject2).toString(), "");
return
(byte[])localObject1;
}
catch (Exception localException)
{
localObject1
=
new StringBuilder();
((StringBuilder)localObject1).append(
"calShareKeyByBouncycastle failed "
);
((StringBuilder)localObject1).append(pkcs8PrivateKey.toString());
((StringBuilder)localObject1).append(
" peer public key "
);
((StringBuilder)localObject1).append(util.buf_to_string(paramArrayOfByte));
util.LOGI(((StringBuilder)localObject1).toString(), "");
util.printException(localException);
t.ap.attr_api(
2459818
);
return
null;
}
catch (ExceptionInInitializerError paramArrayOfByte)
{
localObject1
=
new StringBuilder();
((StringBuilder)localObject1).append(
"create key failed ExceptionInInitializerError, "
);
((StringBuilder)localObject1).append(paramArrayOfByte.getMessage());
util.LOGW(((StringBuilder)localObject1).toString(), "");
t.ap.attr_api(
2459818
);
}
return
null;
}