AES解密測試
This commit is contained in:
parent
59271ce709
commit
89e4373d81
@ -9,7 +9,7 @@
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:822566078854:android:9cafc8bca8f63076bf8407",
|
||||
"android_client_info": {
|
||||
"package_name": "com.newpdlive.sy"
|
||||
"package_name": "com.pdsylive.yo"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
@ -17,7 +17,7 @@
|
||||
"client_id": "822566078854-8c7698l64j66ijng9bq799o5qvbguhdo.apps.googleusercontent.com",
|
||||
"client_type": 1,
|
||||
"android_info": {
|
||||
"package_name": "com.newpdlive.sy",
|
||||
"package_name": "com.pdsylive.yo",
|
||||
"certificate_hash": "e059b937bfa49d58f40fddee4c7463e03e2aae47"
|
||||
}
|
||||
},
|
||||
@ -25,7 +25,7 @@
|
||||
"client_id": "822566078854-9cej31ie42tgjeimdk691gmvkavrooa7.apps.googleusercontent.com",
|
||||
"client_type": 1,
|
||||
"android_info": {
|
||||
"package_name": "com.newpdlive.sy",
|
||||
"package_name": "com.pdsylive.yo",
|
||||
"certificate_hash": "15fc5e70cf238323bf7111c8c627803985478e87"
|
||||
}
|
||||
},
|
||||
@ -33,7 +33,7 @@
|
||||
"client_id": "822566078854-c63gcmvkn2ctfct9eebuo0r4tiolloel.apps.googleusercontent.com",
|
||||
"client_type": 1,
|
||||
"android_info": {
|
||||
"package_name": "com.newpdlive.sy",
|
||||
"package_name": "com.pdsylive.yo",
|
||||
"certificate_hash": "b66dc8d21cfcf6c729577ddcf0c312b2a31ed872"
|
||||
}
|
||||
},
|
||||
@ -41,7 +41,7 @@
|
||||
"client_id": "822566078854-jfpovcealtjkv6sf0338to2grv4e5i6k.apps.googleusercontent.com",
|
||||
"client_type": 1,
|
||||
"android_info": {
|
||||
"package_name": "com.newpdlive.sy",
|
||||
"package_name": "com.pdsylive.yo",
|
||||
"certificate_hash": "38cc19306c9facee36a9224e9a4070bc0be15c7d"
|
||||
}
|
||||
},
|
||||
|
@ -1,31 +1,53 @@
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
public class AesUtils {
|
||||
|
||||
public static String decrypt(String encrypted) {
|
||||
/**
|
||||
* 使用AES/ECB/PKCS5Padding模式解密数据
|
||||
*
|
||||
* @param encryptedData 加密后的字节数组(Base64解码后的结果,如果原始数据是Base64编码的话)
|
||||
* @param keyBytes AES密钥(16/24/32字节长,对应AES-128/192/256)
|
||||
* @return 解密后的明文字节数组,如果解密失败则返回null
|
||||
*/
|
||||
public static byte[] decrypt(byte[] encryptedData, byte[] keyBytes) {
|
||||
try {
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec("76b60dd0a5d7cafdqqew".getBytes(), "AES");
|
||||
Cipher cipher = Cipher.getInstance("AES");
|
||||
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
|
||||
byte[] original = cipher.doFinal(hexToByteArray(encrypted));
|
||||
return new String(original);
|
||||
// 创建密钥规格
|
||||
SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES-128-ECB");
|
||||
|
||||
// 获取Cipher实例并初始化为解密模式
|
||||
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, keySpec);
|
||||
// 执行解密
|
||||
byte[] decryptedBytes = cipher.doFinal(encryptedData);
|
||||
// 返回解密后的字节数组
|
||||
return decryptedBytes;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
return null; // 解密失败时返回null
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] hexToByteArray(String hex) {
|
||||
if (hex == null || hex.length() == 0) {
|
||||
return null;
|
||||
/**
|
||||
* 如果需要将解密后的字节数组转换为字符串(注意:这可能会导致数据丢失或乱码)
|
||||
*
|
||||
* @param encryptedData 加密后的字节数组(或Base64解码后的结果)
|
||||
* @param keyBytes AES密钥
|
||||
* @param charset 用于将解密后的字节数组转换为字符串的字符集
|
||||
* @return 解密后的字符串,如果解密失败则返回null
|
||||
*/
|
||||
public static String decryptToString(byte[] encryptedData, byte[] keyBytes, String charset) {
|
||||
byte[] decryptedBytes = decrypt(encryptedData, keyBytes);
|
||||
if (decryptedBytes != null) {
|
||||
// 尝试将字节数组转换为字符串(使用指定的字符集)
|
||||
try {
|
||||
return new String(decryptedBytes, charset);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
byte[] ba = new byte[hex.length() / 2];
|
||||
for (int i = 0; i < ba.length; i++) {
|
||||
ba[i] = (byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16);
|
||||
}
|
||||
return ba;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -648,7 +648,7 @@
|
||||
<string name="welcome_pdlive">歡迎來到PDLIVE</string>
|
||||
<string name="newcomer">恭喜你獲得了新人獎勵</string>
|
||||
|
||||
<string name="FILE_PROVIDER">com.newpdlive.sy.fileprovider</string>
|
||||
<string name="FILE_PROVIDER">com.pdsylive.yo.fileprovider</string>
|
||||
<string name="ren">人</string>
|
||||
<string name="ge">個</string>
|
||||
<string name="count">數量</string>
|
||||
|
@ -60,7 +60,6 @@ import com.yunbao.common.CommonAppContext;
|
||||
import com.yunbao.common.bean.QiniuLog;
|
||||
import com.yunbao.common.glide.ImgLoader;
|
||||
import com.yunbao.common.server.DownloadService;
|
||||
import com.yunbao.common.utils.AesUtils;
|
||||
import com.yunbao.common.utils.AppManager;
|
||||
import com.yunbao.common.utils.L;
|
||||
import com.yunbao.common.utils.LogUtil;
|
||||
@ -581,35 +580,6 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
|
||||
//获取声网Token
|
||||
getSwToken();
|
||||
initLogUpdate();
|
||||
testAes();
|
||||
}
|
||||
|
||||
private void testAes() {
|
||||
StringBuffer aesStr =new StringBuffer();
|
||||
aesStr.append("U2FsdGVkX18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opTxqPQd42YVbcKfx8UAVt55pXrszA\n" +
|
||||
"IrnuHeQUfXqIeUHCtOLSeyxi7eK8ztVyEOmKyG7ho9KqmpR7EvVEtcPHVCj/J1rf\n" +
|
||||
"1tIZl3efl1vBSJj5UzpPXTDXdmojODnxZyZqkXc8H2fqPRCcaS7HqMnPkln1BLCh\n" +
|
||||
"8Eon6QAT8lXBLHSnPLlCVDOG1ZteE2xPwi4745NF5Tz2i1D8mZPvUIgZaV73D1WR\n" +
|
||||
"cdGDMG9s+okiMx2K5imiOyH6VjHixrsiuxYmPvDGEGetIJKUmrhTXHjXQUMMP/wx\n" +
|
||||
"dASbECKoO0ic7k7PwwE8Ekpo7zVtK7tkmYUwA6Fi2VBLiwS0r89H+9gTw9dJfsqR\n" +
|
||||
"HcyiWOuP/z/Pzaaoa3XqvjLZYGAtCFJac0MRFZAHsWtZw8tz+KCYw3nG+RDCXmKC\n" +
|
||||
"jpzU4/Jv9ARo8vQAdBm+Dw==");
|
||||
String msg = AesUtils.decrypt(aesStr.toString());
|
||||
L.e("解密:"+msg);
|
||||
}
|
||||
|
||||
private void getSwToken() {
|
||||
|
@ -19,8 +19,10 @@ import com.lxj.xpopup.core.BottomPopupView;
|
||||
import com.yunbao.common.dialog.GiftWallDialog;
|
||||
import com.yunbao.common.manager.IMLoginManager;
|
||||
import com.yunbao.common.manager.RandomSudGameManager;
|
||||
import com.yunbao.common.utils.AesUtils;
|
||||
import com.yunbao.common.utils.AppManager;
|
||||
import com.yunbao.common.utils.DebugUtils;
|
||||
import com.yunbao.common.utils.L;
|
||||
import com.yunbao.common.utils.MobclickAgent;
|
||||
import com.yunbao.common.activity.AbsActivity;
|
||||
import com.yunbao.common.event.FloatWarOrderEvent;
|
||||
@ -33,6 +35,8 @@ import com.yunbao.main.R;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/9/22.
|
||||
* MainActivity 首页 删除
|
||||
@ -79,7 +83,8 @@ public class MainHomeViewHolder extends AbsMainHomeParentViewHolder {
|
||||
IMLoginManager.get(mContext).getUserInfo().getUserNicename(), null
|
||||
, false).setFullWindows(true).setTab2(true).showDialog();*/
|
||||
// RouteUtil.forwardBattlePass();
|
||||
RandomSudGameManager.getManager().random(mContext);
|
||||
//RandomSudGameManager.getManager().random(mContext);
|
||||
testAes();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
@ -93,7 +98,16 @@ public class MainHomeViewHolder extends AbsMainHomeParentViewHolder {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void testAes() {
|
||||
String aesStr ="yvNHDY/jYopEYMnjYKzm5p0WfeP/IqahmtN/zY8kH5MYiLn1K6P57c+JkIBTySvRDcULlZCNJEPynx0Z6PcPwfLpWHTniDNKRYo3Hiw1iwI=";
|
||||
//byte[] msg = AesUtils.decrypt(aesStr.getBytes(), "LhHBfcsN2VmBpHCn".getBytes());
|
||||
byte[] decodedData = null;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
decodedData = Base64.getDecoder().decode(aesStr);
|
||||
}
|
||||
String decryptedText = AesUtils.decryptToString(decodedData, "LhHBfcsN2VmBpHCn".getBytes(), "UTF-8");
|
||||
L.e("decryptedText:"+decryptedText);
|
||||
}
|
||||
public void setCurPosition(int position) {
|
||||
mViewPager.setCurrentItem(position);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user