Commit dc4c934e authored by fengruiyu's avatar fengruiyu

项目正常跑起来

parent 7c16a2b2
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="1.8" />
<bytecodeTargetLevel target="11" />
</component>
</project>
\ No newline at end of file
......@@ -5,10 +5,13 @@
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
</configurations>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
<component name="SuppressKotlinCodeStyleNotification">
<option name="disableForAll" value="true" />
</component>
</project>
\ No newline at end of file
......@@ -3,6 +3,7 @@
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
......
......@@ -10,6 +10,10 @@ android {
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName
//flavorDimensions "default"
buildConfigField ("boolean","IS_DEV","false")
}
dataBinding {
......@@ -19,31 +23,50 @@ android {
sourceCompatibility rootProject.ext.java_version["compileJavaVersion"]
targetCompatibility rootProject.ext.java_version["targetJavaVersion"]
}
productFlavors {
// 开发版本
auto {
buildConfigField ('boolean','IS_DEV',"true")
manifestPlaceholders = [
app_logo_name: "Auto"
]
}
// 线上产品版本
product {
buildConfigField ('boolean','IS_DEV',"false")
manifestPlaceholders = [
app_logo_name: "线上"
]
}
}
// buildTypes {
// debug {
// minifyEnabled false
// //signingConfig signingConfigs.release
// zipAlignEnabled true
// versionNameSuffix "-dev"
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// }
// release {
// minifyEnabled false
// zipAlignEnabled true
// shrinkResources false
// //signingConfig signingConfigs.release
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// }
// }
// productFlavors {
// // 开发版本
// auto {
// buildConfigField ('boolean','IS_DEV',"true")
// manifestPlaceholders = [
// app_logo_name: "Auto"
// ]
// }
// // 线上产品版本
// product {
// buildConfigField ('boolean','IS_DEV',"false")
// manifestPlaceholders = [
// app_logo_name: "线上"
// ]
// }
// }
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
testImplementation rootProject.ext.support["junit"]
// implementation 'androidx.appcompat:appcompat:1.1.0'
// implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// testImplementation 'junit:junit:4.12'
// androidTestImplementation 'androidx.test.ext:junit:1.1.1'
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
api project(':library_base')
......
# 环境名
name=product
api.base.url=https://
isProduct=true
\ No newline at end of file
# 环境名 默认
name=test
api.base.url=http://apitest.
isProduct=false
\ No newline at end of file
{
"supplier":{
"vivo":{
"appid":"103881568"
},
"xiaomi":{
"appid": "2882303761518348857"
},
"huawei":{
"appid": "101833995"
},
"oppo":{
"appid": "30251013"
}
}
}
# 环境名
name=product
api.base.url=https://api.
isProduct=true
\ No newline at end of file
{
"supplier":{
"vivo":{
"appid":"103881568"
},
"xiaomi":{
"appid": "2882303761518348857"
},
"huawei":{
"appid": "101833995"
},
"oppo":{
"appid": "30251013"
}
}
}
......@@ -15,8 +15,11 @@ android {
versionName rootProject.ext.android.versionName
flavorDimensions '23'
multiDexEnabled true
buildConfigField ("boolean","IS_DEV","false")
buildConfigField ("String","AppKeyPre","abcd")
buildConfigField ("boolean","IS_DEV","false")
//从com.android.tools.build:gradle:4.1.0开始,build.gradle文件正式移除了versionName和versionCode,参照Android开发者官网。
buildConfigField ("String","VERSION_NAME", "\"" + rootProject.ext.android.versionName + "\"")
buildConfigField ("String","VERSION_CODE", "\"" + rootProject.ext.android.versionCode + "\"")
buildConfigField ("String","AppKeyPre","\"" + "abcd" + "\"")
}
......@@ -52,17 +55,17 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
//包含所有环境
auto {
buildConfigField ("boolean","IS_DEV","true")
}
// 线上产品版本
product {
buildConfigField ("boolean","IS_DEV","false")
}
}
// productFlavors {
// //包含所有环境
// auto {
// buildConfigField ("boolean","IS_DEV","true")
// }
// // 线上产品版本
// product {
// buildConfigField ("boolean","IS_DEV","false")
// }
// }
//
compileOptions {
sourceCompatibility rootProject.ext.java_version["compileJavaVersion"]
......
......@@ -23,13 +23,13 @@ android {
buildConfigField ("int","BUILD_VERSION","${buildVersion}")
}
// noArg {
// annotation("com.jeme.base.annotation.Poko")
// }
//
// allOpen {
// annotation("com.jeme.base.annotation.Poko")
// }
noArg {
annotation("com.jeme.base.annotation.Poko")
}
allOpen {
annotation("com.jeme.base.annotation.Poko")
}
}
dependencies {
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
......
......@@ -4,9 +4,7 @@ import android.app.Application;
import android.view.Gravity;
import com.alibaba.android.arouter.launcher.ARouter;
import com.fry.base.BuildConfig;
import com.fry.base.global.Constants;
import com.fry.base.utils.PropertyUtils;
import com.tencent.bugly.crashreport.CrashReport;
import me.goldze.mvvmhabit.utils.KLog;
......@@ -21,15 +19,14 @@ import me.goldze.mvvmhabit.utils.ToastUtils;
public class BaseModuleInit implements IModuleInit<Void> {
@Override
public boolean onInitAhead(Application application,boolean isMainProcess) {
// 环境配置读取初始化优先级最高,要先初始化
PropertyUtils.init(application);
//开启打印日志
KLog.init(BuildConfig.DEBUG);
//初始化阿里路由框架
if (BuildConfig.DEBUG) {
ARouter.openLog(); // 打印日志
ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险)
}
// KLog.init(BuildConfig.DEBUG);
// //初始化阿里路由框架
// if (BuildConfig.DEBUG) {
// ARouter.openLog(); // 打印日志
// ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险)
// }
// 尽可能早,推荐在Application中初始化
ARouter.init(application);
ToastUtils.setGravity(Gravity.CENTER,0,0);
......@@ -42,9 +39,9 @@ public class BaseModuleInit implements IModuleInit<Void> {
// 这里实现SDK初始化,appId替换成你的在Bugly平台申请的appId
// 调试时,将第三个参数改为true
// Bugly.init(application, Constants.BUGLY_APP_ID, BuildConfig.IS_DEV);
if(!BuildConfig.IS_DEV && ! SPUtils2.getInstance().decodeBoolean("isFirstOpen", true)){
CrashReport.initCrashReport(application, Constants.BUGLY_APP_ID, false);
}
// if(!BuildConfig.IS_DEV && ! SPUtils2.getInstance().decodeBoolean("isFirstOpen", true)){
// CrashReport.initCrashReport(application, Constants.BUGLY_APP_ID, false);
// }
return null;
}
......
package com.fry.base.global;
import com.fry.base.utils.PropertyUtils;
/**
* Created by jeme on 2019/9/17
*/
......@@ -56,6 +54,8 @@ public class Constants {
}
public static String getBaseUrl() {
return PropertyUtils.getApiBaseUrl();
//fry
// return PropertyUtils.getApiBaseUrl();
return "";
}
}
}
\ No newline at end of file
......@@ -52,7 +52,9 @@ public class InitConstants {
public static int getVersionCode() {
if (VERSION_CODE == null) {
return BuildConfig.VERSION_CODE;
//fry
//return BuildConfig.VERSION_CODE;
return 0;
}
return VERSION_CODE;
}
......@@ -66,6 +68,7 @@ public class InitConstants {
public static String getVersionName() {
if (VERSION_NAME == null) {
return BuildConfig.VERSION_NAME;
return "";
}
return VERSION_NAME;
}
......
package com.fry.base.netwrok
import android.text.TextUtils
import android.util.Log
import com.fry.base.bean.AppRequest
import com.fry.base.utils.encry.AESUtils
import com.fry.base.utils.encry.Base64
import com.fry.base.utils.encry.MD5
import com.google.gson.Gson
import okhttp3.*
import okio.Buffer
import org.json.JSONObject
import java.io.IOException
import java.io.UnsupportedEncodingException
import java.nio.charset.Charset
/**
* 拦截器
*/
class OkHttpInterceptor(aesKey: String) : Interceptor {
private var aesKey = ""
/**
* 实例化拦截器对象
*/
init {
this.aesKey = aesKey
}
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
// val tokenID: String = UserManager.INSTANCE.getTokenID()
val tokenID: String = ""
val time = System.currentTimeMillis()
val channel = createChannel()
var request = chain.request()
// 加密
request = encrypt(request, tokenID, time, channel)
// header
val builder = addHeader(request, tokenID, time, channel)
// 解密
var response = chain.proceed(builder)
response = decrypt(response)
return response
}
/**
* 创建渠道
*
* @return
*/
private fun createChannel(): String {
var channel: String = ""
// var channel: String = CommonUtils.getAppMetaData(App.instance, "CHANNEL_NAME")
// try {
// // 穿山甲分包渠道
// val ttChannel = HumeSDK.getChannel(App.instance)
// if (!TextUtils.isEmpty(ttChannel)) {
// // 此处方式不能修改,已和后端约定
// channel = channel + "_" + ttChannel
// }
// } catch (e: Exception) {
// e.printStackTrace()
// }
return channel
}
/**
* 添加header
*
* @param request
* @param tokenID
* @param time
* @param channel
* @return
*/
@Throws(UnsupportedEncodingException::class)
private fun addHeader(request: Request, tokenID: String, time: Long, channel: String): Request {
return request.newBuilder()
.addHeader("version", BuildConfig.VERSION_NAME)
.addHeader("token", tokenID)
.addHeader("channel", channel)
.addHeader("new-session", MD5.GetMD5Code(time.toString()))
.addHeader("last-session", Base64.encode(time.toString().toByteArray(charset("UTF-8"))))
.build()
}
/**
* json加密
*
* @param request
* @param tokenID
* @param time
* @param channel
* @return
* @throws IOException
*/
@Throws(IOException::class)
private fun encrypt(request: Request, tokenID: String, time: Long, channel: String): Request {
//获取请求body,只有@Body 参数的requestBody 才不会为 null
var request = request
val requestBody = request.body
if (requestBody != null) {
val buffer = Buffer()
requestBody.writeTo(buffer)
var charset = Charset.forName("UTF-8")
val contentType = requestBody.contentType()
if (contentType != null) {
charset = contentType.charset(charset)
}
// 原始报文
var valueStr = buffer.readString(charset!!)
val checkStr = valueStr
//加密
if (isSign(request) && !TextUtils.isEmpty(valueStr)) {
valueStr = AESUtils.encrypt(valueStr, aesKey)
}
// 渠道
val channelName = "android_$channel"
// sign
val requestSign = "$tokenID:$channelName:$time"
val sign = MD5.GetMD5Code(requestSign)
// 验证
val check = MD5.GetMD5Code("$requestSign:$checkStr")
val appRequest = AppRequest(channelName, sign, check, valueStr)
val body: RequestBody = RequestBody.create(contentType, Gson().toJson(appRequest))
request = request.newBuilder()
.post(body)
.build()
}
return request
}
/**
* json解密
*
* @param response
* @return
* @throws IOException
*/
@Throws(IOException::class)
private fun decrypt(response: Response): Response {
var response = response
if (response.isSuccessful && isSign(response.request)) {
//the response data
val body = response.body
val source = body!!.source()
source.request(Long.MAX_VALUE) // Buffer the entire body.
val buffer = source.buffer()
var charset = Charset.defaultCharset()
val contentType = body.contentType()
if (contentType != null) {
charset = contentType.charset(charset)
}
var rspString: String? = buffer.clone().readString(charset!!)
// 解密
try {
val json = JSONObject(rspString)
if (!json.isNull("data")) {
val data = json["data"]
rspString = AESUtils.detrypt(data.toString(), aesKey)
val jsonArray = JSONObject(rspString)
json.put("data", jsonArray)
rspString = json.toString()
// rspString = json.toString().replace("\\", "");
}
} catch (e: Exception) {
Log.d("OkHttpInterceptor", "json解密失败。url:${response.request.url}响应报文:${buffer.clone().readString(charset)}")
e.printStackTrace()
}
val responseBody = ResponseBody.create(contentType, rspString!!)
response = response.newBuilder().body(responseBody).build()
}
return response
}
/**
* 是否加/解密 - 接口非common都加/解密
*
* @param request
* @return true=加/解密
*/
private fun isSign(request: Request): Boolean {
val url = request.url.toString()
//是否加密标识
var isSign = true
if (!TextUtils.isEmpty(url)) {
isSign = !url.contains("common/")
}
return isSign
}
package com.fry.base.netwrok
import android.text.TextUtils
import android.util.Log
import com.fry.base.BuildConfig
import com.fry.base.bean.AppRequest
import com.fry.base.utils.encry.AESUtils
import com.fry.base.utils.encry.Base64
import com.fry.base.utils.encry.MD5
import com.google.gson.Gson
import okhttp3.*
import okio.Buffer
import org.json.JSONObject
import java.io.IOException
import java.io.UnsupportedEncodingException
import java.nio.charset.Charset
/**
* 拦截器
*/
class OkHttpInterceptor(aesKey: String) : Interceptor {
private var aesKey = ""
/**
* 实例化拦截器对象
*/
init {
this.aesKey = aesKey
}
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
// val tokenID: String = UserManager.INSTANCE.getTokenID()
val tokenID: String = ""
val time = System.currentTimeMillis()
val channel = createChannel()
var request = chain.request()
// 加密
request = encrypt(request, tokenID, time, channel)
// header
val builder = addHeader(request, tokenID, time, channel)
// 解密
var response = chain.proceed(builder)
response = decrypt(response)
return response
}
/**
* 创建渠道
*
* @return
*/
private fun createChannel(): String {
var channel: String = ""
// var channel: String = CommonUtils.getAppMetaData(App.instance, "CHANNEL_NAME")
// try {
// // 穿山甲分包渠道
// val ttChannel = HumeSDK.getChannel(App.instance)
// if (!TextUtils.isEmpty(ttChannel)) {
// // 此处方式不能修改,已和后端约定
// channel = channel + "_" + ttChannel
// }
// } catch (e: Exception) {
// e.printStackTrace()
// }
return channel
}
/**
* 添加header
*
* @param request
* @param tokenID
* @param time
* @param channel
* @return
*/
@Throws(UnsupportedEncodingException::class)
private fun addHeader(request: Request, tokenID: String, time: Long, channel: String): Request {
return request.newBuilder()
.addHeader("version", BuildConfig.VERSION_NAME)
.addHeader("token", tokenID)
.addHeader("channel", channel)
.addHeader("new-session", MD5.GetMD5Code(time.toString()))
.addHeader("last-session", Base64.encode(time.toString().toByteArray(charset("UTF-8"))))
.build()
}
/**
* json加密
*
* @param request
* @param tokenID
* @param time
* @param channel
* @return
* @throws IOException
*/
@Throws(IOException::class)
private fun encrypt(request: Request, tokenID: String, time: Long, channel: String): Request {
//获取请求body,只有@Body 参数的requestBody 才不会为 null
var request = request
val requestBody = request.body
if (requestBody != null) {
val buffer = Buffer()
requestBody.writeTo(buffer)
var charset = Charset.forName("UTF-8")
val contentType = requestBody.contentType()
if (contentType != null) {
charset = contentType.charset(charset)
}
// 原始报文
var valueStr = buffer.readString(charset!!)
val checkStr = valueStr
//加密
if (isSign(request) && !TextUtils.isEmpty(valueStr)) {
valueStr = AESUtils.encrypt(valueStr, aesKey)
}
// 渠道
val channelName = "android_$channel"
// sign
val requestSign = "$tokenID:$channelName:$time"
val sign = MD5.GetMD5Code(requestSign)
// 验证
val check = MD5.GetMD5Code("$requestSign:$checkStr")
val appRequest = AppRequest(channelName, sign, check, valueStr)
val body: RequestBody = RequestBody.create(contentType, Gson().toJson(appRequest))
request = request.newBuilder()
.post(body)
.build()
}
return request
}
/**
* json解密
*
* @param response
* @return
* @throws IOException
*/
@Throws(IOException::class)
private fun decrypt(response: Response): Response {
var response = response
if (response.isSuccessful && isSign(response.request)) {
//the response data
val body = response.body
val source = body!!.source()
source.request(Long.MAX_VALUE) // Buffer the entire body.
val buffer = source.buffer()
var charset = Charset.defaultCharset()
val contentType = body.contentType()
if (contentType != null) {
charset = contentType.charset(charset)
}
var rspString: String? = buffer.clone().readString(charset!!)
// 解密
try {
val json = JSONObject(rspString)
if (!json.isNull("data")) {
val data = json["data"]
rspString = AESUtils.detrypt(data.toString(), aesKey)
val jsonArray = JSONObject(rspString)
json.put("data", jsonArray)
rspString = json.toString()
// rspString = json.toString().replace("\\", "");
}
} catch (e: Exception) {
Log.d("OkHttpInterceptor", "json解密失败。url:${response.request.url}响应报文:${buffer.clone().readString(charset)}")
e.printStackTrace()
}
val responseBody = ResponseBody.create(contentType, rspString!!)
response = response.newBuilder().body(responseBody).build()
}
return response
}
/**
* 是否加/解密 - 接口非common都加/解密
*
* @param request
* @return true=加/解密
*/
private fun isSign(request: Request): Boolean {
val url = request.url.toString()
//是否加密标识
var isSign = true
if (!TextUtils.isEmpty(url)) {
isSign = !url.contains("common/")
}
return isSign
}
}
\ No newline at end of file
package com.fry.base.utils;
import android.content.Context;
import androidx.annotation.StringDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Field;
/**
* 2019-10-18 created
*
* @author KOM
*/
public class BuildConfigUtils {
/**
* 在build.gradle中配置字段的KEY
*/
@StringDef({ConfigField.DEBUG, ConfigField.APPLICATION_ID,
ConfigField.BUILD_TYPE, ConfigField.FLAVOR,
ConfigField.VERSION_CODE, ConfigField.VERSION_NAME})
@Retention(RetentionPolicy.SOURCE)
public @interface ConfigField {
String DEBUG = "DEBUG";
String APPLICATION_ID = "APPLICATION_ID";
String BUILD_TYPE = "BUILD_TYPE";
String FLAVOR = "FLAVOR";
String VERSION_CODE = "VERSION_CODE";
String VERSION_NAME = "VERSION_NAME";
}
/**
* 获取APP模块下配置的 buildConfigField 的值
*/
public static <T> T getBuildConfigValue(Context context, @ConfigField String fieldName) {
try {
Class<?> clazz = Class.forName(context.getPackageName() + ".BuildConfig");
Field field = clazz.getField(fieldName);
return (T) field.get(null);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
}
package com.fry.base.utils;
import androidx.annotation.StringDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* 2019-10-18 created
*
* @author KOM
*/
@StringDef({PropertyKey.BASE_URL,PropertyKey.IS_PRODUCT})
@Retention(RetentionPolicy.SOURCE)
public @interface PropertyKey {
String NAME = "name";
String BASE_URL = "api.base.url";
String IS_PRODUCT = "isProduct";
}
package com.fry.base.utils;
import android.content.Context;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import me.goldze.mvvmhabit.utils.Utils;
/**
* 2019-10-18 created
*
* @author KOM
*/
public class PropertyUtils {
private static Properties mProps = new Properties();
private static boolean mHasLoadProps = false;
private static final Object mLock = new Object();
private static final String TAG = "PropertyUtils";
public PropertyUtils() {
}
/**
* 初始化 级别应该最高
*/
public static void init(Context context) {
if (!mHasLoadProps) {
synchronized (mLock) {
if (!mHasLoadProps) {
try {
ConfigManager.EnvironmentType environmentType = ConfigManager.getDefault().getAppEnv();
InputStream is = context.getAssets().open(environmentType.configType+".properties");
mProps.load(is);
mHasLoadProps = true;
Log.d("PropertyUtils", "load config.properties successfully!");
} catch (IOException var4) {
Log.e("PropertyUtils", "load config.properties error!", var4);
}
}
}
}
}
public static String getApiBaseUrl() {
if (mProps == null) {
throw new IllegalArgumentException("must call #UtilsManager.init(context) in application");
} else {
return mProps.getProperty(PropertyKey.BASE_URL, "");
}
}
public static boolean isProduct() {
return mProps.getProperty(PropertyKey.IS_PRODUCT, "false").equals("true");
}
public static String getEnvironmentName() {
return mProps.getProperty(PropertyKey.NAME, "");
}
public static ConfigManager.EnvironmentType environmentMap() {
String envName = getEnvironmentName();
switch (envName){
case "product":
return ConfigManager.EnvironmentType.PRODUCT;
default:
return ConfigManager.EnvironmentType.TEST;
}
}
public static boolean isDebug() {
Boolean isDebug = BuildConfigUtils.getBuildConfigValue(
Utils.getContext(), BuildConfigUtils.ConfigField.DEBUG);
return isDebug == null ? true : isDebug;
}
public static String getValueByKey(String key) {
return mProps.getProperty(key, "");
}
}
package com.fry.base.utils.encry;
import android.util.Log;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import Decoder.BASE64Decoder;
import Decoder.BASE64Encoder;
public class AESUtils {
private static final String vis = MD5.GetMD5Code("goldcamera_2021").substring(8, 24);
// public static final String key = "123456";
public static String CIPHER_ALGORITHM = "AES/CBC/PKCS5Padding"; // optional value AES/DES/DESede
private static SecretKeySpec getKey(String strKey) throws Exception {
byte[] arrBTmp = strKey.getBytes();
byte[] arrB = new byte[16]; // 创建一个空的16位字节数组(默认值为0)
for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
arrB[i] = arrBTmp[i];
}
SecretKeySpec skeySpec = new SecretKeySpec(arrB, "AES");
return skeySpec;
}
public static String encrypt(String message, String key) {
try {
SecretKeySpec skeySpec = getKey(key);
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
IvParameterSpec iv = new IvParameterSpec(vis.getBytes());
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
byte[] encrypted = cipher.doFinal(message.getBytes("UTF-8"));
return new BASE64Encoder().encode(encrypted);
} catch (Exception e) {
}
return "";
}
public static String detrypt(String message, String key) {
try {
byte[] res = new BASE64Decoder().decodeBuffer(message);
SecretKeySpec skeySpec = getKey(key);
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
IvParameterSpec iv = new IvParameterSpec(vis.getBytes());
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
byte[] detrypted = cipher.doFinal(res);
return new String(detrypted, "UTF-8");
} catch (Exception e) {
}
return "";
}
private static String getBK1() {
return BuildConfig.AppKeyPre;
}
private static String getBK2() {
return "nnnnnn";
}
private static String getBK3(int size) {
StringBuffer sb = new StringBuffer();
for (int i = 1; i <= size; i++) {
sb.append(i);
}
return sb.toString();
}
public static String getDefaultKey() {
StringBuffer sb = new StringBuffer();
sb.append(getBK1())
.append(getBK2())
.append(getBK3(6));
return sb.toString();
}
}
package com.fry.base.utils.encry;
import android.util.Log;
import com.fry.base.BuildConfig;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import Decoder.BASE64Decoder;
import Decoder.BASE64Encoder;
public class AESUtils {
private static final String vis = MD5.GetMD5Code("goldcamera_2021").substring(8, 24);
// public static final String key = "123456";
public static String CIPHER_ALGORITHM = "AES/CBC/PKCS5Padding"; // optional value AES/DES/DESede
private static SecretKeySpec getKey(String strKey) throws Exception {
byte[] arrBTmp = strKey.getBytes();
byte[] arrB = new byte[16]; // 创建一个空的16位字节数组(默认值为0)
for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
arrB[i] = arrBTmp[i];
}
SecretKeySpec skeySpec = new SecretKeySpec(arrB, "AES");
return skeySpec;
}
public static String encrypt(String message, String key) {
try {
SecretKeySpec skeySpec = getKey(key);
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
IvParameterSpec iv = new IvParameterSpec(vis.getBytes());
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
byte[] encrypted = cipher.doFinal(message.getBytes("UTF-8"));
return new BASE64Encoder().encode(encrypted);
} catch (Exception e) {
}
return "";
}
public static String detrypt(String message, String key) {
try {
byte[] res = new BASE64Decoder().decodeBuffer(message);
SecretKeySpec skeySpec = getKey(key);
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
IvParameterSpec iv = new IvParameterSpec(vis.getBytes());
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
byte[] detrypted = cipher.doFinal(res);
return new String(detrypted, "UTF-8");
} catch (Exception e) {
}
return "";
}
private static String getBK1() {
return BuildConfig.AppKeyPre;
}
private static String getBK2() {
return "nnnnnn";
}
private static String getBK3(int size) {
StringBuffer sb = new StringBuffer();
for (int i = 1; i <= size; i++) {
sb.append(i);
}
return sb.toString();
}
public static String getDefaultKey() {
StringBuffer sb = new StringBuffer();
sb.append(getBK1())
.append(getBK2())
.append(getBK3(6));
return sb.toString();
}
}
#Wed Jun 30 17:38:32 CST 2021
VERSION_BUILD=2228
#Wed Jun 30 19:52:15 CST 2021
VERSION_BUILD=2320
......@@ -19,7 +19,9 @@ android {
}
dependencies {
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
//implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
provided files('libs\\xpopup-release.aar')
//support
api rootProject.ext.support["support-v4"]
api rootProject.ext.support["appcompat-v7"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment