feat:替换加密方式;引入阿里utdid后续设备ID应该用的到
This commit is contained in:
@@ -689,34 +689,6 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
}).compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取手机验证码
|
||||
*
|
||||
* @param phone
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Single<String> getSMSCode(String phone) {
|
||||
Map<String, String> paramsEncrypt = new HashMap<>();
|
||||
paramsEncrypt.put("phone", phone);
|
||||
String paramsStr = "";
|
||||
String signStr = "";
|
||||
try {
|
||||
paramsStr = APIEncryptUtil.encryptParams(paramsEncrypt);
|
||||
signStr = APIEncryptUtil.paramsToSign(paramsEncrypt);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return api.getSMSCode(paramsStr, signStr).flatMap(new Function<ServiceResult, SingleSource<String>>() {
|
||||
@Override
|
||||
public SingleSource<String> apply(ServiceResult serviceResult) throws Exception {
|
||||
if (!serviceResult.isSuccess()) {
|
||||
return Single.error(new Throwable(serviceResult.getMessage()));
|
||||
}
|
||||
return Single.just("获取手机验证码成功");
|
||||
}
|
||||
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册
|
||||
|
@@ -91,13 +91,6 @@ public interface IAuthModel extends IModel{
|
||||
*/
|
||||
Single<String> bindPhone(String phone, String code);
|
||||
|
||||
/**
|
||||
* 获取手机验证码
|
||||
* @param phone
|
||||
* @return
|
||||
*/
|
||||
Single<String> getSMSCode(String phone);
|
||||
|
||||
/**
|
||||
* 注册
|
||||
* @param phone
|
||||
|
@@ -1,8 +1,6 @@
|
||||
package com.nnbc123.core.utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.nnbc123.xchat_android_constants.XChatConstants;
|
||||
import com.nnbc123.library.utils.codec.DESUtils;
|
||||
import com.nnbc123.library.utils.codec.MD5Utils;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
@@ -23,18 +21,6 @@ public class APIEncryptUtil {
|
||||
private static final String DES_ENCRYPT_KEY_SMS_PARAMS = XChatConstants.DES_ENCRYPT_KEY_SMS_PARAMS;
|
||||
private static final String DES_ENCRYPT_KEY_SMS_SIGN = XChatConstants.DES_ENCRYPT_KEY_SMS_SIGN;
|
||||
|
||||
|
||||
/**
|
||||
* 参数加密
|
||||
* @param params
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encryptParams(Map<String,String> params) throws Exception{
|
||||
String json = new Gson().toJson(params);
|
||||
return DESUtils.DESAndBase64Encrypt(json,DES_ENCRYPT_KEY_SMS_PARAMS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成签名
|
||||
* @param params
|
||||
|
@@ -24,9 +24,6 @@ public interface IWithdrawModel extends IModel{
|
||||
// 兑换接口,发起兑换
|
||||
Single<ExchangerInfo> requestExchange(long uid, int pid, String pwd, int accountType);
|
||||
|
||||
//获取手机验证码
|
||||
Single<String> getSmsCode(long uid, String ticket);
|
||||
|
||||
//绑定支付宝
|
||||
Single<String> binderAlipay(String aliPayAccount, String aliPayAccountName, String code);
|
||||
|
||||
|
@@ -113,34 +113,7 @@ public class WithdrawModel extends BaseModel implements IWithdrawModel {
|
||||
});
|
||||
|
||||
}
|
||||
//获取绑定支付宝验证码
|
||||
@Override
|
||||
public Single<String> getSmsCode(long uid, String ticket) {
|
||||
Map<String, String> paramsEncrypt = new HashMap<>();
|
||||
paramsEncrypt.put("ticket", ticket);
|
||||
paramsEncrypt.put("uid", String.valueOf(uid));
|
||||
String paramsStr = null;
|
||||
String signStr = null;
|
||||
try {
|
||||
paramsStr = APIEncryptUtil.encryptParams(paramsEncrypt);
|
||||
signStr = APIEncryptUtil.paramsToSign(paramsEncrypt);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return api.getSms(
|
||||
paramsStr,
|
||||
signStr
|
||||
)
|
||||
.flatMap((Function<ServiceResult, SingleSource<String>>) serviceResult -> {
|
||||
String msg = serviceResult == null ? "" : serviceResult.getMessage();
|
||||
if (serviceResult != null && serviceResult.isSuccess()) {
|
||||
return Single.just(msg);
|
||||
}
|
||||
return Single.error(new Throwable(msg));
|
||||
})
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
|
||||
}
|
||||
//绑定支付宝
|
||||
@Override
|
||||
public Single<String> binderAlipay(String aliPayAccount, String aliPayAccountName, String code) {
|
||||
|
@@ -26,6 +26,9 @@ android {
|
||||
sourceSets {
|
||||
|
||||
main {
|
||||
|
||||
jniLibs.srcDirs = ['libs']
|
||||
|
||||
java.srcDirs = [
|
||||
'src/main/java',
|
||||
'src/module_easypermission/java',
|
||||
@@ -34,6 +37,7 @@ android {
|
||||
'src/module_common/java',
|
||||
'src/module_core/java',
|
||||
'src/module_utils/java',
|
||||
'src/module_encrypt/java',
|
||||
|
||||
]
|
||||
|
||||
@@ -44,6 +48,7 @@ android {
|
||||
'src/module_common/res',
|
||||
'src/module_core/res',
|
||||
'src/module_utils/res',
|
||||
'src/module_encrypt/res',
|
||||
|
||||
]
|
||||
|
||||
@@ -143,6 +148,8 @@ dependencies {
|
||||
api 'com.facebook.stetho:stetho-okhttp3:1.5.1'
|
||||
|
||||
api 'com.geyifeng.immersionbar:immersionbar:3.2.2'
|
||||
|
||||
api files("libs/alicloud-android-utdid-2.6.0.jar")
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
BIN
library/libs/alicloud-android-utdid-2.6.0.jar
Normal file
BIN
library/libs/alicloud-android-utdid-2.6.0.jar
Normal file
Binary file not shown.
BIN
library/libs/arm64-v8a/libencrypt.so
Executable file
BIN
library/libs/arm64-v8a/libencrypt.so
Executable file
Binary file not shown.
BIN
library/libs/armeabi-v7a/libencrypt.so
Executable file
BIN
library/libs/armeabi-v7a/libencrypt.so
Executable file
Binary file not shown.
BIN
library/libs/x86/libencrypt.so
Executable file
BIN
library/libs/x86/libencrypt.so
Executable file
Binary file not shown.
BIN
library/libs/x86_64/libencrypt.so
Executable file
BIN
library/libs/x86_64/libencrypt.so
Executable file
Binary file not shown.
@@ -1,89 +1,19 @@
|
||||
package com.nnbc123.library.utils.codec;
|
||||
|
||||
import com.example.lib_encrypt.EncryptLib;
|
||||
import com.nnbc123.library.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* /**
|
||||
*
|
||||
* @author liuguofu
|
||||
*/
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
import com.nnbc123.library.utils.StringUtils;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.Key;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.spec.DESKeySpec;
|
||||
|
||||
//import sun.misc.BASE64Decoder;
|
||||
//import sun.misc.BASE64Encoder;
|
||||
|
||||
|
||||
public class DESUtils {
|
||||
|
||||
// static BASE64Decoder decoder = new BASE64Decoder();
|
||||
// static BASE64Encoder encoder = new BASE64Encoder();
|
||||
|
||||
static String DES = "DES";
|
||||
static String ENCODE = "UTF-8";//保持平台兼容统一使用utf-8
|
||||
|
||||
//des 加密
|
||||
private static byte[] encryptByteDES(byte[] byteD, String strKey) throws Exception {
|
||||
return doEncrypt(byteD, getKey(strKey), DES);
|
||||
}
|
||||
|
||||
//des 解密
|
||||
private static byte[] decryptByteDES(byte[] byteD, String strKey) throws Exception {
|
||||
return doDecrypt(byteD, getKey(strKey), DES);
|
||||
}
|
||||
|
||||
public static SecretKey getKey(String strKey) throws Exception {
|
||||
DESKeySpec desKeySpec = new DESKeySpec(strKey.getBytes());
|
||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
|
||||
SecretKey sk = keyFactory.generateSecret(desKeySpec);
|
||||
return sk;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
String text = "admin";
|
||||
// String pwd = "NJD783iSDK0d9fjd98KKDf9O";
|
||||
String pwd = "1ea53d260ecf11e7b56e00163e046a26";
|
||||
//客户端加密
|
||||
// String data = DESAndBase64Encrypt(text, pwd);
|
||||
// System.out.println("text DES加密后base64:" + URLEncoder.encode(data, "UTF-8"));
|
||||
|
||||
//服务端解密
|
||||
// String textDecrypt = DESAndBase64Decrypt(data, pwd);
|
||||
// System.out.println("未处理原文:" + text);
|
||||
// System.out.println("解密后数据:" + textDecrypt);
|
||||
|
||||
|
||||
// byte[] bytes = text.getBytes();
|
||||
// byte[] encode = Base64.encode(bytes,Base64.DEFAULT);
|
||||
|
||||
}
|
||||
|
||||
//客户端加密
|
||||
public static String DESAndBase64Encrypt(String dataToEncrypt, String secretKey) throws Exception {
|
||||
byte[] encryptData = encryptByteDES(dataToEncrypt.getBytes(ENCODE), secretKey);//这里加密前不要处理加密数据的空格换行等事情
|
||||
byte[] encode = Base64.encode(encryptData, Base64.DEFAULT);
|
||||
String dataBase64 = StringUtils.toEncodedString(encode, Charset.defaultCharset());
|
||||
return replaceBlank(dataBase64);
|
||||
}
|
||||
|
||||
//客户端加密
|
||||
public static String DESAndBase64Encrypt(String dataToEncypt) throws Exception {
|
||||
byte[] encryptData = encryptByteDES(replaceBlank(dataToEncypt).getBytes(ENCODE), "1ea53d260ecf11e7b56e00163e046a26");
|
||||
byte[] encode = Base64.encode(encryptData, Base64.DEFAULT);
|
||||
String dataBase64 = StringUtils.toEncodedString(encode, Charset.defaultCharset());
|
||||
return replaceBlank(dataBase64);
|
||||
public static String DESAndBase64Encrypt(String dataToEncrypt) throws Exception {
|
||||
return EncryptLib.INSTANCE.encryptTextDef1(dataToEncrypt);
|
||||
}
|
||||
|
||||
public static String DESAndBase64(String psw) {
|
||||
@@ -96,52 +26,16 @@ public class DESUtils {
|
||||
return pwd;
|
||||
}
|
||||
|
||||
public static String replaceBlank(String str) {
|
||||
String dest = "";
|
||||
if (str != null) {
|
||||
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
|
||||
Matcher m = p.matcher(str);
|
||||
dest = m.replaceAll("");
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
//服务端解密
|
||||
public static String DESAndBase64Decrypt(String dataBase64) throws Exception {
|
||||
if (StringUtils.isEmpty(dataBase64)) return null;
|
||||
byte[] encryptedData = Base64.decode(dataBase64, Base64.DEFAULT);
|
||||
byte[] decryptedData = decryptByteDES(encryptedData, "1ea53d260ecf11e7b56e00163e046a26");
|
||||
String textDecrypt = new String(decryptedData, ENCODE);
|
||||
return textDecrypt;
|
||||
return EncryptLib.INSTANCE.decryptTextDef1(dataBase64);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行加密操作
|
||||
*
|
||||
* @param data 待操作数据
|
||||
* @param key Key
|
||||
* @param type 算法 RSA or DES
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static byte[] doEncrypt(byte[] data, Key key, String type) throws Exception {
|
||||
Cipher cipher = Cipher.getInstance(type);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, key);
|
||||
return cipher.doFinal(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行解密操作
|
||||
*
|
||||
* @param data 待操作数据
|
||||
* @param key Key
|
||||
* @param type 算法 RSA or DES
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static byte[] doDecrypt(byte[] data, Key key, String type) throws Exception {
|
||||
Cipher cipher = Cipher.getInstance(type);
|
||||
cipher.init(Cipher.DECRYPT_MODE, key);
|
||||
return cipher.doFinal(data);
|
||||
//解密
|
||||
public static String decryptDef2(String dataBase64) throws Exception {
|
||||
if (StringUtils.isEmpty(dataBase64)) return null;
|
||||
return EncryptLib.INSTANCE.decryptTextDef2(dataBase64);
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
package com.example.lib_encrypt
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
object EncryptLib {
|
||||
|
||||
init {
|
||||
System.loadLibrary("encrypt")
|
||||
}
|
||||
|
||||
fun encryptText(enc: String, key: String): String {
|
||||
return replaceBlank(encrypt(replaceBlank(enc), key) ?: "")
|
||||
}
|
||||
|
||||
fun decryptText(dec: String, key: String): String {
|
||||
return decrypt(dec, key) ?: ""
|
||||
}
|
||||
|
||||
fun encryptTextDef1(enc: String): String {
|
||||
return replaceBlank(encryptDef(replaceBlank(enc)) ?: "")
|
||||
}
|
||||
|
||||
fun decryptTextDef1(dec: String): String {
|
||||
return decryptDef(dec) ?: ""
|
||||
}
|
||||
|
||||
fun encryptTextDef2(enc: String): String {
|
||||
return replaceBlank(encryptDef2(replaceBlank(enc)) ?: "")
|
||||
}
|
||||
|
||||
fun decryptTextDef2(dec: String): String {
|
||||
return decryptDef2(dec) ?: ""
|
||||
}
|
||||
|
||||
private fun replaceBlank(str: String): String {
|
||||
val p = Pattern.compile("\\s*|\t|\r|\n")
|
||||
val m = p.matcher(str)
|
||||
return m.replaceAll("")
|
||||
}
|
||||
|
||||
// DES
|
||||
private external fun encrypt(enc: String, key: String): String?
|
||||
|
||||
// DES
|
||||
private external fun decrypt(dec: String, key: String): String?
|
||||
|
||||
// DES-默认KEY1
|
||||
private external fun encryptDef(enc: String): String?
|
||||
|
||||
// DES-默认KEY1(1ea53d26)
|
||||
private external fun decryptDef(dec: String): String?
|
||||
|
||||
// DES-默认KEY2
|
||||
private external fun encryptDef2(enc: String): String?
|
||||
|
||||
// DES-默认KEY2(9fa73e66)
|
||||
private external fun decryptDef2(dec: String): String?
|
||||
}
|
Reference in New Issue
Block a user