@onekeyfe/react-native-jpush 0.0.0-stage → 6.7.0-alpha.435
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +23 -2
- package/ReactNativeJpush.podspec +66 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +143 -0
- package/android/gradle.properties +4 -0
- package/android/src/main/AndroidManifest.xml +143 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/cn/android/service/JTransitActivity.java +19 -0
- package/android/src/main/java/cn/jiguang/android/BuildConfig.java +10 -0
- package/android/src/main/java/cn/jiguang/android/IDataShare.java +190 -0
- package/android/src/main/java/cn/jiguang/api/BaseLogger.java +82 -0
- package/android/src/main/java/cn/jiguang/api/JAction.java +22 -0
- package/android/src/main/java/cn/jiguang/api/JActionExtra.java +21 -0
- package/android/src/main/java/cn/jiguang/api/JAnalyticsAction.java +11 -0
- package/android/src/main/java/cn/jiguang/api/JCoreInterface.java +228 -0
- package/android/src/main/java/cn/jiguang/api/JCoreManager.java +156 -0
- package/android/src/main/java/cn/jiguang/api/JDispatchAction.java +66 -0
- package/android/src/main/java/cn/jiguang/api/MultiSpHelper.java +114 -0
- package/android/src/main/java/cn/jiguang/api/ReportCallBack.java +9 -0
- package/android/src/main/java/cn/jiguang/api/SdkType.java +13 -0
- package/android/src/main/java/cn/jiguang/api/utils/JCollectionAuth.java +23 -0
- package/android/src/main/java/cn/jiguang/core/JCoreCrypto.java +545 -0
- package/android/src/main/java/cn/jiguang/core/JCoreStorage.java +737 -0
- package/android/src/main/java/cn/jiguang/core/JCoreTcpEngine.java +1394 -0
- package/android/src/main/java/cn/jiguang/core/JCoreWireCodec.java +1716 -0
- package/android/src/main/java/cn/jiguang/internal/ActionManager.java +63 -0
- package/android/src/main/java/cn/jiguang/internal/JConstants.java +61 -0
- package/android/src/main/java/cn/jiguang/internal/JCoreHelperAction.java +12 -0
- package/android/src/main/java/cn/jiguang/internal/JCoreInternalHelper.java +102 -0
- package/android/src/main/java/cn/jiguang/net/DefaultHostVerifier.java +40 -0
- package/android/src/main/java/cn/jiguang/net/HttpRequest.java +78 -0
- package/android/src/main/java/cn/jiguang/net/HttpResponse.java +48 -0
- package/android/src/main/java/cn/jiguang/net/HttpUtils.java +106 -0
- package/android/src/main/java/cn/jiguang/plugins/core/JCoreModule.java +91 -0
- package/android/src/main/java/cn/jiguang/plugins/core/JCorePackage.java +27 -0
- package/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java +773 -0
- package/android/src/main/java/cn/jiguang/plugins/push/JPushPackage.java +25 -0
- package/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java +88 -0
- package/android/src/main/java/cn/jiguang/plugins/push/common/JLogger.java +122 -0
- package/android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java +710 -0
- package/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushBroadcastReceiver.java +37 -0
- package/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushModuleReceiver.java +264 -0
- package/android/src/main/java/cn/jiguang/plugins/service/JCoreModuleService.java +7 -0
- package/android/src/main/java/cn/jpush/android/api/BasicPushNotificationBuilder.java +83 -0
- package/android/src/main/java/cn/jpush/android/api/CallBackParams.java +50 -0
- package/android/src/main/java/cn/jpush/android/api/CmdMessage.java +33 -0
- package/android/src/main/java/cn/jpush/android/api/CustomMessage.java +28 -0
- package/android/src/main/java/cn/jpush/android/api/CustomPushNotificationBuilder.java +81 -0
- package/android/src/main/java/cn/jpush/android/api/DefaultPushNotificationBuilder.java +90 -0
- package/android/src/main/java/cn/jpush/android/api/InAppSlotParams.java +65 -0
- package/android/src/main/java/cn/jpush/android/api/InstrumentedActivity.java +17 -0
- package/android/src/main/java/cn/jpush/android/api/InstrumentedListActivity.java +17 -0
- package/android/src/main/java/cn/jpush/android/api/JPushInterface.java +488 -0
- package/android/src/main/java/cn/jpush/android/api/JPushMessage.java +121 -0
- package/android/src/main/java/cn/jpush/android/api/JThirdPlatFormInterface.java +147 -0
- package/android/src/main/java/cn/jpush/android/api/MultiActionsNotificationBuilder.java +72 -0
- package/android/src/main/java/cn/jpush/android/api/NotificationCustomButton.java +50 -0
- package/android/src/main/java/cn/jpush/android/api/NotificationMessage.java +67 -0
- package/android/src/main/java/cn/jpush/android/api/PushNotificationBuilder.java +13 -0
- package/android/src/main/java/cn/jpush/android/api/TagAliasCallback.java +8 -0
- package/android/src/main/java/cn/jpush/android/data/JPushCollectControl.java +96 -0
- package/android/src/main/java/cn/jpush/android/data/JPushConfig.java +79 -0
- package/android/src/main/java/cn/jpush/android/data/JPushConfigEx.java +41 -0
- package/android/src/main/java/cn/jpush/android/data/JPushLocalNotification.java +155 -0
- package/android/src/main/java/cn/jpush/android/helper/JCoreHelper.java +70 -0
- package/android/src/main/java/cn/jpush/android/helper/Logger.java +82 -0
- package/android/src/main/java/cn/jpush/android/local/ActionHelper.java +1198 -0
- package/android/src/main/java/cn/jpush/android/local/ActivityLifeCallBack.java +47 -0
- package/android/src/main/java/cn/jpush/android/local/JPushAction.java +67 -0
- package/android/src/main/java/cn/jpush/android/local/JPushConstants.java +34 -0
- package/android/src/main/java/cn/jpush/android/local/JPushResponse.java +26 -0
- package/android/src/main/java/cn/jpush/android/local/ProxyActivityAction.java +34 -0
- package/android/src/main/java/cn/jpush/android/service/AlarmReceiver.java +15 -0
- package/android/src/main/java/cn/jpush/android/service/BActivity.java +19 -0
- package/android/src/main/java/cn/jpush/android/service/DActivity.java +19 -0
- package/android/src/main/java/cn/jpush/android/service/DaemonService.java +17 -0
- package/android/src/main/java/cn/jpush/android/service/DataProvider.java +136 -0
- package/android/src/main/java/cn/jpush/android/service/DataShare.java +129 -0
- package/android/src/main/java/cn/jpush/android/service/DownloadProvider.java +139 -0
- package/android/src/main/java/cn/jpush/android/service/InitProvider.java +48 -0
- package/android/src/main/java/cn/jpush/android/service/JCommonService.java +79 -0
- package/android/src/main/java/cn/jpush/android/service/JNotifyActivity.java +28 -0
- package/android/src/main/java/cn/jpush/android/service/JPushMessageReceiver.java +93 -0
- package/android/src/main/java/cn/jpush/android/service/PushReceiver.java +26 -0
- package/android/src/main/java/cn/jpush/android/service/PushService.java +28 -0
- package/android/src/main/java/cn/jpush/android/service/SchedulerReceiver.java +17 -0
- package/android/src/main/java/cn/jpush/android/service/TagAliasReceiver.java +11 -0
- package/android/src/main/java/cn/jpush/android/service/WakedResultReceiver.java +24 -0
- package/android/src/main/java/cn/jpush/android/ui/FullScreenView.java +11 -0
- package/android/src/main/java/cn/jpush/android/ui/PopWinActivity.java +16 -0
- package/android/src/main/java/cn/jpush/android/ui/PushActivity.java +27 -0
- package/android/src/main/java/cn/jpush/android/ui/RoundedImageView.java +63 -0
- package/android/src/main/java/cn/jpush/android/ui/ShadowViewCard.java +56 -0
- package/android/src/main/java/cn/jpush/android/ups/ICallbackResult.java +5 -0
- package/android/src/main/java/cn/jpush/android/ups/JPushUPSManager.java +37 -0
- package/android/src/main/java/cn/jpush/android/ups/TokenResult.java +47 -0
- package/android/src/main/java/cn/jpush/android/ups/UPSRegisterCallBack.java +4 -0
- package/android/src/main/java/cn/jpush/android/ups/UPSTurnCallBack.java +4 -0
- package/android/src/main/java/cn/jpush/android/ups/UPSUnRegisterCallBack.java +4 -0
- package/android/src/main/java/com/margelo/nitro/reactnativejpush/ReactNativeJpush.kt +455 -0
- package/android/src/main/java/com/margelo/nitro/reactnativejpush/ReactNativeJpushPackage.kt +50 -0
- package/android/src/main/res/values/jpush_string.xml +7 -0
- package/android/src/main/res/values/jpush_style.xml +22 -0
- package/android/src/test/java/com/margelo/nitro/reactnativejpush/ReactNativeJpushProtocolTest.java +1016 -0
- package/ios/ReactNativeJpush.swift +522 -0
- package/ios/bridge/RCTJCoreModule.h +5 -0
- package/ios/bridge/RCTJCoreModule.m +31 -0
- package/ios/bridge/RCTJPushEventQueue.h +14 -0
- package/ios/bridge/RCTJPushEventQueue.m +23 -0
- package/ios/bridge/RCTJPushModule.h +37 -0
- package/ios/bridge/RCTJPushModule.m +1165 -0
- package/ios/include/JCOREService.h +3 -0
- package/ios/include/JGCOREAPI.h +14 -0
- package/ios/include/JGInforCollectionAuth.h +17 -0
- package/ios/include/JGInforCollectionAuthItems.h +2 -0
- package/ios/include/JGPushNotificationTrigger.h +2 -0
- package/ios/include/JPUSHService.h +359 -0
- package/ios/jcore/JCOREConfiguration.h +141 -0
- package/ios/jcore/JCOREConfiguration.m +703 -0
- package/ios/jcore/JCORECrypto.h +73 -0
- package/ios/jcore/JCORECrypto.m +649 -0
- package/ios/jcore/JCORESisResolver.h +56 -0
- package/ios/jcore/JCORESisResolver.m +525 -0
- package/ios/jcore/JCORETcpSession.h +42 -0
- package/ios/jcore/JCORETcpSession.m +956 -0
- package/ios/jcore/JCOREWireProtocol.h +274 -0
- package/ios/jcore/JCOREWireProtocol.m +1453 -0
- package/ios/jpush/JPUSHModels.m +214 -0
- package/ios/jpush/JPUSHNotificationManager.h +34 -0
- package/ios/jpush/JPUSHNotificationManager.m +360 -0
- package/ios/jpush/JPUSHService.m +794 -0
- package/ios/tests/ReactNativeJpushTests.m +148 -0
- package/lib/module/ReactNativeJpush.nitro.js +4 -0
- package/lib/module/ReactNativeJpush.nitro.js.map +1 -0
- package/lib/module/index.js +801 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/ReactNativeJpush.nitro.d.ts +60 -0
- package/lib/typescript/src/ReactNativeJpush.nitro.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +235 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/nitro.json +23 -0
- package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string_std__string.hpp +76 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeJpushSpec.cpp +310 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeJpushSpec.hpp +115 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativejpush/Func_void_bool.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativejpush/Func_void_std__string_std__string.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativejpush/HybridReactNativeJpushSpec.kt +274 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativejpush/reactnativejpushOnLoad.kt +35 -0
- package/nitrogen/generated/android/reactnativejpush+autolinking.cmake +81 -0
- package/nitrogen/generated/android/reactnativejpush+autolinking.gradle +27 -0
- package/nitrogen/generated/android/reactnativejpushOnLoad.cpp +58 -0
- package/nitrogen/generated/android/reactnativejpushOnLoad.hpp +34 -0
- package/nitrogen/generated/ios/ReactNativeJpush+autolinking.rb +62 -0
- package/nitrogen/generated/ios/ReactNativeJpush-Swift-Cxx-Bridge.cpp +49 -0
- package/nitrogen/generated/ios/ReactNativeJpush-Swift-Cxx-Bridge.hpp +147 -0
- package/nitrogen/generated/ios/ReactNativeJpush-Swift-Cxx-Umbrella.hpp +46 -0
- package/nitrogen/generated/ios/ReactNativeJpushAutolinking.mm +33 -0
- package/nitrogen/generated/ios/ReactNativeJpushAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeJpushSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeJpushSpecSwift.hpp +402 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeJpushSpec.swift +107 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeJpushSpec_cxx.swift +723 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeJpushSpec.cpp +73 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeJpushSpec.hpp +116 -0
- package/package.json +173 -4
- package/src/ReactNativeJpush.nitro.ts +93 -0
- package/src/index.tsx +1090 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package cn.jiguang.api.utils;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import cn.jiguang.core.JCoreStorage;
|
|
5
|
+
|
|
6
|
+
public class JCollectionAuth {
|
|
7
|
+
public static void setAuth(Context context, boolean auth) {
|
|
8
|
+
JCoreStorage.setCollectionAuth(context, auth);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public static boolean isAuth(Context context) {
|
|
12
|
+
return JCoreStorage.isCollectionAuth(context);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public static void enableAutoWakeup(Context context, boolean enable) {
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public static void enableDynamicLoad(Context context, boolean enable) {
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public static void enableAppTerminate(Context context, boolean enable) {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
package cn.jiguang.core;
|
|
2
|
+
|
|
3
|
+
import java.io.ByteArrayInputStream;
|
|
4
|
+
import java.io.ByteArrayOutputStream;
|
|
5
|
+
import java.nio.charset.StandardCharsets;
|
|
6
|
+
import java.security.KeyFactory;
|
|
7
|
+
import java.security.MessageDigest;
|
|
8
|
+
import java.security.PrivateKey;
|
|
9
|
+
import java.security.PublicKey;
|
|
10
|
+
import java.security.SecureRandom;
|
|
11
|
+
import java.security.spec.PKCS8EncodedKeySpec;
|
|
12
|
+
import java.security.spec.X509EncodedKeySpec;
|
|
13
|
+
import java.util.Arrays;
|
|
14
|
+
import java.util.zip.GZIPInputStream;
|
|
15
|
+
import java.util.zip.GZIPOutputStream;
|
|
16
|
+
import javax.crypto.Cipher;
|
|
17
|
+
import javax.crypto.Mac;
|
|
18
|
+
import javax.crypto.spec.IvParameterSpec;
|
|
19
|
+
import javax.crypto.spec.SecretKeySpec;
|
|
20
|
+
|
|
21
|
+
public final class JCoreCrypto {
|
|
22
|
+
private static final int[] MULTIPLIERS = { 8, 5, 23, 3, 13, 17, 7, 31, 29, 37 };
|
|
23
|
+
private static final int[] MODULI = { 74, 88, 15, 73, 96, 49, 68, 39, 41, 91 };
|
|
24
|
+
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
|
|
25
|
+
private static final String HTTP_REPORT_IV_BASE64 = "aW9wMjAzMDQwNTA2YVBrIQ==";
|
|
26
|
+
private static final char[] BASE64_ALPHABET =
|
|
27
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
|
|
28
|
+
private static final int[] BASE64_DECODE_TABLE = new int[128];
|
|
29
|
+
|
|
30
|
+
static {
|
|
31
|
+
Arrays.fill(BASE64_DECODE_TABLE, -1);
|
|
32
|
+
for (int i = 0; i < BASE64_ALPHABET.length; i++) {
|
|
33
|
+
BASE64_DECODE_TABLE[BASE64_ALPHABET[i]] = i;
|
|
34
|
+
}
|
|
35
|
+
BASE64_DECODE_TABLE['-'] = 62;
|
|
36
|
+
BASE64_DECODE_TABLE['_'] = 63;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private static final int[] SM4_FK = {
|
|
40
|
+
0xa3b1bac6, 0x56aa3350, 0x677d9197, 0xb27022dc
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
private static final int[] SM4_CK = {
|
|
44
|
+
0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269,
|
|
45
|
+
0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9,
|
|
46
|
+
0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249,
|
|
47
|
+
0x50575e65, 0x6c737a81, 0x888f969d, 0xa4abb2b9,
|
|
48
|
+
0xc0c7ced5, 0xdce3eaf1, 0xf8ff060d, 0x141b2229,
|
|
49
|
+
0x30373e45, 0x4c535a61, 0x686f767d, 0x848b9299,
|
|
50
|
+
0xa0a7aeb5, 0xbcc3cad1, 0xd8dfe6ed, 0xf4fb0209,
|
|
51
|
+
0x10171e25, 0x2c333a41, 0x484f565d, 0x646b7279
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
private static final byte[] SM4_SBOX = {
|
|
55
|
+
(byte) 0xd6, (byte) 0x90, (byte) 0xe9, (byte) 0xfe, (byte) 0xcc, (byte) 0xe1, (byte) 0x3d, (byte) 0xb7,
|
|
56
|
+
(byte) 0x16, (byte) 0xb6, (byte) 0x14, (byte) 0xc2, (byte) 0x28, (byte) 0xfb, (byte) 0x2c, (byte) 0x05,
|
|
57
|
+
(byte) 0x2b, (byte) 0x67, (byte) 0x9a, (byte) 0x76, (byte) 0x2a, (byte) 0xbe, (byte) 0x04, (byte) 0xc3,
|
|
58
|
+
(byte) 0xaa, (byte) 0x44, (byte) 0x13, (byte) 0x26, (byte) 0x49, (byte) 0x86, (byte) 0x06, (byte) 0x99,
|
|
59
|
+
(byte) 0x9c, (byte) 0x42, (byte) 0x50, (byte) 0xf4, (byte) 0x91, (byte) 0xef, (byte) 0x98, (byte) 0x7a,
|
|
60
|
+
(byte) 0x33, (byte) 0x54, (byte) 0x0b, (byte) 0x43, (byte) 0xed, (byte) 0xcf, (byte) 0xac, (byte) 0x62,
|
|
61
|
+
(byte) 0xe4, (byte) 0xb3, (byte) 0x1c, (byte) 0xa9, (byte) 0xc9, (byte) 0x08, (byte) 0xe8, (byte) 0x95,
|
|
62
|
+
(byte) 0x80, (byte) 0xdf, (byte) 0x94, (byte) 0xfa, (byte) 0x75, (byte) 0x8f, (byte) 0x3f, (byte) 0xa6,
|
|
63
|
+
(byte) 0x47, (byte) 0x07, (byte) 0xa7, (byte) 0xfc, (byte) 0xf3, (byte) 0x73, (byte) 0x17, (byte) 0xba,
|
|
64
|
+
(byte) 0x83, (byte) 0x59, (byte) 0x3c, (byte) 0x19, (byte) 0xe6, (byte) 0x85, (byte) 0x4f, (byte) 0xa8,
|
|
65
|
+
(byte) 0x68, (byte) 0x6b, (byte) 0x81, (byte) 0xb2, (byte) 0x71, (byte) 0x64, (byte) 0xda, (byte) 0x8b,
|
|
66
|
+
(byte) 0xf8, (byte) 0xeb, (byte) 0x0f, (byte) 0x4b, (byte) 0x70, (byte) 0x56, (byte) 0x9d, (byte) 0x35,
|
|
67
|
+
(byte) 0x1e, (byte) 0x24, (byte) 0x0e, (byte) 0x5e, (byte) 0x63, (byte) 0x58, (byte) 0xd1, (byte) 0xa2,
|
|
68
|
+
(byte) 0x25, (byte) 0x22, (byte) 0x7c, (byte) 0x3b, (byte) 0x01, (byte) 0x21, (byte) 0x78, (byte) 0x87,
|
|
69
|
+
(byte) 0xd4, (byte) 0x00, (byte) 0x46, (byte) 0x57, (byte) 0x9f, (byte) 0xd3, (byte) 0x27, (byte) 0x52,
|
|
70
|
+
(byte) 0x4c, (byte) 0x36, (byte) 0x02, (byte) 0xe7, (byte) 0xa0, (byte) 0xc4, (byte) 0xc8, (byte) 0x9e,
|
|
71
|
+
(byte) 0xea, (byte) 0xbf, (byte) 0x8a, (byte) 0xd2, (byte) 0x40, (byte) 0xc7, (byte) 0x38, (byte) 0xb5,
|
|
72
|
+
(byte) 0xa3, (byte) 0xf7, (byte) 0xf2, (byte) 0xce, (byte) 0xf9, (byte) 0x61, (byte) 0x15, (byte) 0xa1,
|
|
73
|
+
(byte) 0xe0, (byte) 0xae, (byte) 0x5d, (byte) 0xa4, (byte) 0x9b, (byte) 0x34, (byte) 0x1a, (byte) 0x55,
|
|
74
|
+
(byte) 0xad, (byte) 0x93, (byte) 0x32, (byte) 0x30, (byte) 0xf5, (byte) 0x8c, (byte) 0xb1, (byte) 0xe3,
|
|
75
|
+
(byte) 0x1d, (byte) 0xf6, (byte) 0xe2, (byte) 0x2e, (byte) 0x82, (byte) 0x66, (byte) 0xca, (byte) 0x60,
|
|
76
|
+
(byte) 0xc0, (byte) 0x29, (byte) 0x23, (byte) 0xab, (byte) 0x0d, (byte) 0x53, (byte) 0x4e, (byte) 0x6f,
|
|
77
|
+
(byte) 0xd5, (byte) 0xdb, (byte) 0x37, (byte) 0x45, (byte) 0xde, (byte) 0xfd, (byte) 0x8e, (byte) 0x2f,
|
|
78
|
+
(byte) 0x03, (byte) 0xff, (byte) 0x6a, (byte) 0x72, (byte) 0x6d, (byte) 0x6c, (byte) 0x5b, (byte) 0x51,
|
|
79
|
+
(byte) 0x8d, (byte) 0x1b, (byte) 0xaf, (byte) 0x92, (byte) 0xbb, (byte) 0xdd, (byte) 0xbc, (byte) 0x7f,
|
|
80
|
+
(byte) 0x11, (byte) 0xd9, (byte) 0x5c, (byte) 0x41, (byte) 0x1f, (byte) 0x10, (byte) 0x5a, (byte) 0xd8,
|
|
81
|
+
(byte) 0x0a, (byte) 0xc1, (byte) 0x31, (byte) 0x88, (byte) 0xa5, (byte) 0xcd, (byte) 0x7b, (byte) 0xbd,
|
|
82
|
+
(byte) 0x2d, (byte) 0x74, (byte) 0xd0, (byte) 0x12, (byte) 0xb8, (byte) 0xe5, (byte) 0xb4, (byte) 0xb0,
|
|
83
|
+
(byte) 0x89, (byte) 0x69, (byte) 0x97, (byte) 0x4a, (byte) 0x0c, (byte) 0x96, (byte) 0x77, (byte) 0x7e,
|
|
84
|
+
(byte) 0x65, (byte) 0xb9, (byte) 0xf1, (byte) 0x09, (byte) 0xc5, (byte) 0x6e, (byte) 0xc6, (byte) 0x84,
|
|
85
|
+
(byte) 0x18, (byte) 0xf0, (byte) 0x7d, (byte) 0xec, (byte) 0x3a, (byte) 0xdc, (byte) 0x4d, (byte) 0x20,
|
|
86
|
+
(byte) 0x79, (byte) 0xee, (byte) 0x5f, (byte) 0x3e, (byte) 0xd7, (byte) 0xcb, (byte) 0x39, (byte) 0x48
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
private JCoreCrypto() {
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public static String generateSeedKey(long seed) {
|
|
93
|
+
int index = (int) (Math.abs(seed) % 10L);
|
|
94
|
+
long value = seed * MULTIPLIERS[index] + (seed % MODULI[index]);
|
|
95
|
+
return md5Hex("JCKP" + value);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public static int nextPositiveSeed24() {
|
|
99
|
+
int val = SECURE_RANDOM.nextInt() & 0xFFFFFF;
|
|
100
|
+
return val != 0 ? val : 1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public static int nextRegisterSeed() {
|
|
104
|
+
return Math.abs(SECURE_RANDOM.nextInt(10000000)) + 1;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public static String generateHttpSeedKey() {
|
|
108
|
+
return generateSeedKey(nextRegisterSeed());
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public static byte[] aes256CbcSeedEncrypt(byte[] data, long seed) {
|
|
112
|
+
String key32 = generateSeedKey(seed);
|
|
113
|
+
String iv16 = key32.substring(0, 16);
|
|
114
|
+
return aesCbcEncrypt(data, key32, iv16, 32);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public static byte[] aes256CbcSeedDecrypt(byte[] data, long seed) {
|
|
118
|
+
String key32 = generateSeedKey(seed);
|
|
119
|
+
String iv16 = key32.substring(0, 16);
|
|
120
|
+
return aesCbcDecrypt(data, key32, iv16, 32);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public static byte[] aes256CbcHttpEncrypt(byte[] data, String key32) {
|
|
124
|
+
byte[] iv = base64Decode(HTTP_REPORT_IV_BASE64);
|
|
125
|
+
return doAesCbcBytes(
|
|
126
|
+
Cipher.ENCRYPT_MODE,
|
|
127
|
+
data,
|
|
128
|
+
key32 != null ? key32.getBytes(StandardCharsets.UTF_8) : new byte[0],
|
|
129
|
+
iv,
|
|
130
|
+
32
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public static byte[] aes256CbcHttpDecrypt(byte[] data, String key32) {
|
|
135
|
+
byte[] iv = base64Decode(HTTP_REPORT_IV_BASE64);
|
|
136
|
+
return doAesCbcBytes(
|
|
137
|
+
Cipher.DECRYPT_MODE,
|
|
138
|
+
data,
|
|
139
|
+
key32 != null ? key32.getBytes(StandardCharsets.UTF_8) : new byte[0],
|
|
140
|
+
iv,
|
|
141
|
+
32
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public static byte[] aesCbcEncrypt(byte[] data, String key, String iv, int keyLengthBytes) {
|
|
146
|
+
return doAesCbc(Cipher.ENCRYPT_MODE, data, key, iv, keyLengthBytes);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public static byte[] aesCbcDecrypt(byte[] data, String key, String iv, int keyLengthBytes) {
|
|
150
|
+
return doAesCbc(Cipher.DECRYPT_MODE, data, key, iv, keyLengthBytes);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public static byte[] aesEcbEncrypt(byte[] data, String key, int keyLengthBytes) {
|
|
154
|
+
return doAesEcb(Cipher.ENCRYPT_MODE, data, key, keyLengthBytes);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public static byte[] aesEcbDecrypt(byte[] data, String key, int keyLengthBytes) {
|
|
158
|
+
return doAesEcb(Cipher.DECRYPT_MODE, data, key, keyLengthBytes);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private static byte[] doAesCbc(int mode, byte[] data, String key, String iv, int keyLengthBytes) {
|
|
162
|
+
if (key == null) {
|
|
163
|
+
return new byte[0];
|
|
164
|
+
}
|
|
165
|
+
return doAesCbcBytes(
|
|
166
|
+
mode,
|
|
167
|
+
data,
|
|
168
|
+
key.getBytes(StandardCharsets.UTF_8),
|
|
169
|
+
iv != null ? iv.getBytes(StandardCharsets.UTF_8) : null,
|
|
170
|
+
keyLengthBytes
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private static byte[] doAesCbcBytes(int mode, byte[] data, byte[] rawKey, byte[] rawIv, int keyLengthBytes) {
|
|
175
|
+
if (data == null || data.length == 0 || rawKey == null || rawKey.length == 0) {
|
|
176
|
+
return new byte[0];
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
byte[] normalizedKey = new byte[keyLengthBytes];
|
|
180
|
+
System.arraycopy(rawKey, 0, normalizedKey, 0, Math.min(rawKey.length, keyLengthBytes));
|
|
181
|
+
|
|
182
|
+
byte[] normalizedIv = new byte[16];
|
|
183
|
+
if (rawIv != null) {
|
|
184
|
+
System.arraycopy(rawIv, 0, normalizedIv, 0, Math.min(rawIv.length, 16));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
SecretKeySpec secretKey = new SecretKeySpec(normalizedKey, "AES");
|
|
188
|
+
IvParameterSpec ivSpec = new IvParameterSpec(normalizedIv);
|
|
189
|
+
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
|
190
|
+
cipher.init(mode, secretKey, ivSpec);
|
|
191
|
+
return cipher.doFinal(data);
|
|
192
|
+
} catch (Throwable ignored) {
|
|
193
|
+
return new byte[0];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private static byte[] doAesEcb(int mode, byte[] data, String key, int keyLengthBytes) {
|
|
198
|
+
if (data == null || data.length == 0 || key == null) {
|
|
199
|
+
return new byte[0];
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
byte[] rawKey = key.getBytes(StandardCharsets.UTF_8);
|
|
203
|
+
byte[] normalizedKey = new byte[keyLengthBytes];
|
|
204
|
+
System.arraycopy(rawKey, 0, normalizedKey, 0, Math.min(rawKey.length, keyLengthBytes));
|
|
205
|
+
SecretKeySpec secretKey = new SecretKeySpec(normalizedKey, "AES");
|
|
206
|
+
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
|
207
|
+
cipher.init(mode, secretKey);
|
|
208
|
+
return cipher.doFinal(data);
|
|
209
|
+
} catch (Throwable ignored) {
|
|
210
|
+
return new byte[0];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
public static byte[] sm4CbcSeedEncrypt(byte[] data, long seed) {
|
|
215
|
+
String keyHex = generateSeedKey(seed);
|
|
216
|
+
byte[] key16 = hexDecode(keyHex);
|
|
217
|
+
byte[] iv16 = keyHex.substring(0, 16).getBytes(StandardCharsets.UTF_8);
|
|
218
|
+
return sm4CbcEncrypt(data, key16, iv16);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
public static byte[] sm4CbcSeedDecrypt(byte[] data, long seed) {
|
|
222
|
+
String keyHex = generateSeedKey(seed);
|
|
223
|
+
byte[] key16 = hexDecode(keyHex);
|
|
224
|
+
byte[] iv16 = keyHex.substring(0, 16).getBytes(StandardCharsets.UTF_8);
|
|
225
|
+
return sm4CbcDecrypt(data, key16, iv16);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
public static byte[] sm4CbcEncrypt(byte[] data, byte[] key16, byte[] iv16) {
|
|
229
|
+
if (data == null || key16 == null || key16.length != 16 || iv16 == null || iv16.length < 16) {
|
|
230
|
+
return new byte[0];
|
|
231
|
+
}
|
|
232
|
+
int[] rk = sm4ExpandKey(key16, true);
|
|
233
|
+
int padLen = 16 - (data.length % 16);
|
|
234
|
+
byte[] padded = Arrays.copyOf(data, data.length + padLen);
|
|
235
|
+
for (int i = data.length; i < padded.length; i++) {
|
|
236
|
+
padded[i] = (byte) padLen;
|
|
237
|
+
}
|
|
238
|
+
byte[] out = new byte[padded.length];
|
|
239
|
+
byte[] prev = Arrays.copyOf(iv16, 16);
|
|
240
|
+
byte[] block = new byte[16];
|
|
241
|
+
for (int offset = 0; offset < padded.length; offset += 16) {
|
|
242
|
+
for (int i = 0; i < 16; i++) {
|
|
243
|
+
block[i] = (byte) (padded[offset + i] ^ prev[i]);
|
|
244
|
+
}
|
|
245
|
+
byte[] encBlock = sm4CryptBlock(block, rk);
|
|
246
|
+
System.arraycopy(encBlock, 0, out, offset, 16);
|
|
247
|
+
prev = encBlock;
|
|
248
|
+
}
|
|
249
|
+
return out;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public static byte[] sm4CbcDecrypt(byte[] cipherText, byte[] key16, byte[] iv16) {
|
|
253
|
+
if (cipherText == null || cipherText.length == 0 || (cipherText.length % 16) != 0
|
|
254
|
+
|| key16 == null || key16.length != 16 || iv16 == null || iv16.length < 16) {
|
|
255
|
+
return new byte[0];
|
|
256
|
+
}
|
|
257
|
+
int[] rk = sm4ExpandKey(key16, false);
|
|
258
|
+
byte[] out = new byte[cipherText.length];
|
|
259
|
+
byte[] prev = Arrays.copyOf(iv16, 16);
|
|
260
|
+
byte[] block = new byte[16];
|
|
261
|
+
for (int offset = 0; offset < cipherText.length; offset += 16) {
|
|
262
|
+
System.arraycopy(cipherText, offset, block, 0, 16);
|
|
263
|
+
byte[] decBlock = sm4CryptBlock(block, rk);
|
|
264
|
+
for (int i = 0; i < 16; i++) {
|
|
265
|
+
out[offset + i] = (byte) (decBlock[i] ^ prev[i]);
|
|
266
|
+
}
|
|
267
|
+
System.arraycopy(block, 0, prev, 0, 16);
|
|
268
|
+
}
|
|
269
|
+
int padLen = out[out.length - 1] & 0xFF;
|
|
270
|
+
if (padLen < 1 || padLen > 16 || padLen > out.length) {
|
|
271
|
+
return new byte[0];
|
|
272
|
+
}
|
|
273
|
+
for (int i = out.length - padLen; i < out.length; i++) {
|
|
274
|
+
if ((out[i] & 0xFF) != padLen) {
|
|
275
|
+
return new byte[0];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return Arrays.copyOf(out, out.length - padLen);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
private static int[] sm4ExpandKey(byte[] key16, boolean forEncryption) {
|
|
282
|
+
int[] k = new int[36];
|
|
283
|
+
for (int i = 0; i < 4; i++) {
|
|
284
|
+
k[i] = packBe32(key16, i * 4) ^ SM4_FK[i];
|
|
285
|
+
}
|
|
286
|
+
int[] rk = new int[32];
|
|
287
|
+
for (int i = 0; i < 32; i++) {
|
|
288
|
+
int t = k[i + 1] ^ k[i + 2] ^ k[i + 3] ^ SM4_CK[i];
|
|
289
|
+
int tau = sm4Tau(t);
|
|
290
|
+
int lPrime = tau ^ Integer.rotateLeft(tau, 13) ^ Integer.rotateLeft(tau, 23);
|
|
291
|
+
k[i + 4] = k[i] ^ lPrime;
|
|
292
|
+
rk[forEncryption ? i : (31 - i)] = k[i + 4];
|
|
293
|
+
}
|
|
294
|
+
return rk;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
private static byte[] sm4CryptBlock(byte[] block16, int[] rk) {
|
|
298
|
+
int[] x = new int[36];
|
|
299
|
+
for (int i = 0; i < 4; i++) {
|
|
300
|
+
x[i] = packBe32(block16, i * 4);
|
|
301
|
+
}
|
|
302
|
+
for (int i = 0; i < 32; i++) {
|
|
303
|
+
int t = x[i + 1] ^ x[i + 2] ^ x[i + 3] ^ rk[i];
|
|
304
|
+
int tau = sm4Tau(t);
|
|
305
|
+
int l = tau
|
|
306
|
+
^ Integer.rotateLeft(tau, 2)
|
|
307
|
+
^ Integer.rotateLeft(tau, 10)
|
|
308
|
+
^ Integer.rotateLeft(tau, 18)
|
|
309
|
+
^ Integer.rotateLeft(tau, 24);
|
|
310
|
+
x[i + 4] = x[i] ^ l;
|
|
311
|
+
}
|
|
312
|
+
byte[] out = new byte[16];
|
|
313
|
+
unpackBe32(x[35], out, 0);
|
|
314
|
+
unpackBe32(x[34], out, 4);
|
|
315
|
+
unpackBe32(x[33], out, 8);
|
|
316
|
+
unpackBe32(x[32], out, 12);
|
|
317
|
+
return out;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private static int sm4Tau(int a) {
|
|
321
|
+
int b0 = SM4_SBOX[(a >>> 24) & 0xFF] & 0xFF;
|
|
322
|
+
int b1 = SM4_SBOX[(a >>> 16) & 0xFF] & 0xFF;
|
|
323
|
+
int b2 = SM4_SBOX[(a >>> 8) & 0xFF] & 0xFF;
|
|
324
|
+
int b3 = SM4_SBOX[a & 0xFF] & 0xFF;
|
|
325
|
+
return (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
private static int packBe32(byte[] b, int offset) {
|
|
329
|
+
return ((b[offset] & 0xFF) << 24)
|
|
330
|
+
| ((b[offset + 1] & 0xFF) << 16)
|
|
331
|
+
| ((b[offset + 2] & 0xFF) << 8)
|
|
332
|
+
| (b[offset + 3] & 0xFF);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
private static void unpackBe32(int val, byte[] b, int offset) {
|
|
336
|
+
b[offset] = (byte) (val >>> 24);
|
|
337
|
+
b[offset + 1] = (byte) (val >>> 16);
|
|
338
|
+
b[offset + 2] = (byte) (val >>> 8);
|
|
339
|
+
b[offset + 3] = (byte) val;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
public static byte[] hexDecode(String hex) {
|
|
343
|
+
if (hex == null || (hex.length() & 1) != 0) {
|
|
344
|
+
return new byte[0];
|
|
345
|
+
}
|
|
346
|
+
int len = hex.length() >> 1;
|
|
347
|
+
byte[] out = new byte[len];
|
|
348
|
+
for (int i = 0; i < len; i++) {
|
|
349
|
+
int hi = Character.digit(hex.charAt(i * 2), 16);
|
|
350
|
+
int lo = Character.digit(hex.charAt(i * 2 + 1), 16);
|
|
351
|
+
if (hi < 0 || lo < 0) {
|
|
352
|
+
return new byte[0];
|
|
353
|
+
}
|
|
354
|
+
out[i] = (byte) ((hi << 4) | lo);
|
|
355
|
+
}
|
|
356
|
+
return out;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
public static String hexEncode(byte[] bytes) {
|
|
360
|
+
if (bytes == null || bytes.length == 0) {
|
|
361
|
+
return "";
|
|
362
|
+
}
|
|
363
|
+
StringBuilder sb = new StringBuilder(bytes.length * 2);
|
|
364
|
+
for (byte b : bytes) {
|
|
365
|
+
sb.append(String.format("%02x", b & 0xFF));
|
|
366
|
+
}
|
|
367
|
+
return sb.toString();
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
public static String base64Encode(byte[] data) {
|
|
371
|
+
if (data == null || data.length == 0) {
|
|
372
|
+
return "";
|
|
373
|
+
}
|
|
374
|
+
StringBuilder out = new StringBuilder(((data.length + 2) / 3) * 4);
|
|
375
|
+
int i = 0;
|
|
376
|
+
int len = data.length;
|
|
377
|
+
while (i < len) {
|
|
378
|
+
int b0 = data[i++] & 0xFF;
|
|
379
|
+
int b1 = (i < len) ? (data[i++] & 0xFF) : -1;
|
|
380
|
+
int b2 = (i < len) ? (data[i++] & 0xFF) : -1;
|
|
381
|
+
|
|
382
|
+
out.append(BASE64_ALPHABET[b0 >>> 2]);
|
|
383
|
+
if (b1 < 0) {
|
|
384
|
+
out.append(BASE64_ALPHABET[(b0 & 0x03) << 4]);
|
|
385
|
+
out.append("==");
|
|
386
|
+
} else if (b2 < 0) {
|
|
387
|
+
out.append(BASE64_ALPHABET[((b0 & 0x03) << 4) | (b1 >>> 4)]);
|
|
388
|
+
out.append(BASE64_ALPHABET[(b1 & 0x0F) << 2]);
|
|
389
|
+
out.append('=');
|
|
390
|
+
} else {
|
|
391
|
+
out.append(BASE64_ALPHABET[((b0 & 0x03) << 4) | (b1 >>> 4)]);
|
|
392
|
+
out.append(BASE64_ALPHABET[((b1 & 0x0F) << 2) | (b2 >>> 6)]);
|
|
393
|
+
out.append(BASE64_ALPHABET[b2 & 0x3F]);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return out.toString();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
public static byte[] base64Decode(String input) {
|
|
400
|
+
if (input == null || input.isEmpty()) {
|
|
401
|
+
return new byte[0];
|
|
402
|
+
}
|
|
403
|
+
ByteArrayOutputStream out = new ByteArrayOutputStream((input.length() * 3) / 4);
|
|
404
|
+
int buffer = 0;
|
|
405
|
+
int bitsCollected = 0;
|
|
406
|
+
for (int i = 0; i < input.length(); i++) {
|
|
407
|
+
char c = input.charAt(i);
|
|
408
|
+
if (c == '=') {
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
if (c >= 128) {
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
int val = BASE64_DECODE_TABLE[c];
|
|
415
|
+
if (val < 0) {
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
buffer = (buffer << 6) | val;
|
|
419
|
+
bitsCollected += 6;
|
|
420
|
+
if (bitsCollected >= 8) {
|
|
421
|
+
bitsCollected -= 8;
|
|
422
|
+
out.write((buffer >>> bitsCollected) & 0xFF);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return out.toByteArray();
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
public static String rsaEncryptBase64(String plainText, String publicKeyBase64) {
|
|
429
|
+
if (plainText == null || publicKeyBase64 == null) {
|
|
430
|
+
return "";
|
|
431
|
+
}
|
|
432
|
+
try {
|
|
433
|
+
byte[] keyBytes = base64Decode(publicKeyBase64);
|
|
434
|
+
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
|
|
435
|
+
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
|
436
|
+
PublicKey publicKey = keyFactory.generatePublic(keySpec);
|
|
437
|
+
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
|
|
438
|
+
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
|
439
|
+
byte[] encrypted = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8));
|
|
440
|
+
return base64Encode(encrypted);
|
|
441
|
+
} catch (Throwable ignored) {
|
|
442
|
+
return "";
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
public static String rsaDecryptBase64(String cipherBase64, String privateKeyBase64) {
|
|
447
|
+
if (cipherBase64 == null || privateKeyBase64 == null) {
|
|
448
|
+
return "";
|
|
449
|
+
}
|
|
450
|
+
try {
|
|
451
|
+
byte[] keyBytes = base64Decode(privateKeyBase64);
|
|
452
|
+
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
|
|
453
|
+
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
|
454
|
+
PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
|
|
455
|
+
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
|
|
456
|
+
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
|
457
|
+
byte[] decrypted = cipher.doFinal(base64Decode(cipherBase64));
|
|
458
|
+
return new String(decrypted, StandardCharsets.UTF_8);
|
|
459
|
+
} catch (Throwable ignored) {
|
|
460
|
+
return "";
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
public static byte[] gzipCompress(byte[] input) {
|
|
465
|
+
if (input == null || input.length == 0) {
|
|
466
|
+
return new byte[0];
|
|
467
|
+
}
|
|
468
|
+
try {
|
|
469
|
+
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
470
|
+
GZIPOutputStream gzip = new GZIPOutputStream(out);
|
|
471
|
+
gzip.write(input);
|
|
472
|
+
gzip.finish();
|
|
473
|
+
gzip.close();
|
|
474
|
+
return out.toByteArray();
|
|
475
|
+
} catch (Throwable ignored) {
|
|
476
|
+
return input;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
public static byte[] gzipDecompress(byte[] compressed) {
|
|
481
|
+
if (compressed == null || compressed.length == 0) {
|
|
482
|
+
return new byte[0];
|
|
483
|
+
}
|
|
484
|
+
try {
|
|
485
|
+
ByteArrayInputStream in = new ByteArrayInputStream(compressed);
|
|
486
|
+
GZIPInputStream gzip = new GZIPInputStream(in);
|
|
487
|
+
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
488
|
+
byte[] buffer = new byte[4096];
|
|
489
|
+
int read;
|
|
490
|
+
while ((read = gzip.read(buffer)) != -1) {
|
|
491
|
+
out.write(buffer, 0, read);
|
|
492
|
+
}
|
|
493
|
+
gzip.close();
|
|
494
|
+
return out.toByteArray();
|
|
495
|
+
} catch (Throwable ignored) {
|
|
496
|
+
return compressed;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
public static String md5Hex(String input) {
|
|
501
|
+
if (input == null) {
|
|
502
|
+
return "";
|
|
503
|
+
}
|
|
504
|
+
return digestHex("MD5", input.getBytes(StandardCharsets.UTF_8));
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
public static String sha1Hex(String input) {
|
|
508
|
+
if (input == null) {
|
|
509
|
+
return "";
|
|
510
|
+
}
|
|
511
|
+
return digestHex("SHA-1", input.getBytes(StandardCharsets.UTF_8));
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
public static String sha1Hex(byte[] input) {
|
|
515
|
+
return digestHex("SHA-1", input);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
private static String digestHex(String algorithm, byte[] bytes) {
|
|
519
|
+
if (bytes == null) {
|
|
520
|
+
return "";
|
|
521
|
+
}
|
|
522
|
+
try {
|
|
523
|
+
MessageDigest md = MessageDigest.getInstance(algorithm);
|
|
524
|
+
byte[] digest = md.digest(bytes);
|
|
525
|
+
return hexEncode(digest);
|
|
526
|
+
} catch (Throwable ignored) {
|
|
527
|
+
return "";
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
public static String hmacSha256Hex(String content, String key) {
|
|
532
|
+
if (content == null || key == null) {
|
|
533
|
+
return "";
|
|
534
|
+
}
|
|
535
|
+
try {
|
|
536
|
+
Mac mac = Mac.getInstance("HmacSHA256");
|
|
537
|
+
SecretKeySpec secret = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
|
|
538
|
+
mac.init(secret);
|
|
539
|
+
byte[] digest = mac.doFinal(content.getBytes(StandardCharsets.UTF_8));
|
|
540
|
+
return hexEncode(digest);
|
|
541
|
+
} catch (Throwable ignored) {
|
|
542
|
+
return "";
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|