1
+ package com.stringcare.library
2
+
3
+ import android.content.Context
4
+ import android.content.res.Resources
5
+ import android.os.Build
6
+ import android.support.annotation.StringRes
7
+ import java.nio.charset.Charset
8
+ import java.util.*
9
+
10
+ class CPlusLogic {
11
+
12
+ companion object {
13
+
14
+ /* *
15
+ * Obfuscates the given value
16
+ * @param value
17
+ * @return String
18
+ */
19
+ @JvmStatic
20
+ fun obfuscateV1 (context : Context , value : String ): String? {
21
+ return SC ().jniObfuscateV1(context, getCertificateSHA1Fingerprint(context), value)
22
+ }
23
+
24
+ /* *
25
+ * Reveals the given value
26
+ * @param id
27
+ * @return String
28
+ */
29
+ @JvmStatic
30
+ fun revealV1 (context : Context , @StringRes id : Int ): String? {
31
+ return SC ().jniRevealV1(context, getCertificateSHA1Fingerprint(context), context.getString(id))
32
+ }
33
+
34
+ /* *
35
+ * Reveals the given value
36
+ * @param value
37
+ * @return String
38
+ */
39
+ @JvmStatic
40
+ fun revealV1 (context : Context , value : String ): String? {
41
+ return SC ().jniRevealV1(context, getCertificateSHA1Fingerprint(context), value)
42
+ }
43
+
44
+ /* *
45
+ * Reveals the given value
46
+ * @param id
47
+ * @param formatArgs
48
+ * @return
49
+ */
50
+ @JvmStatic
51
+ fun revealV1 (context : Context , @StringRes id : Int , formatArgs : Array <out Any >): String ? {
52
+ val value = revealV1(context, id)
53
+ value?.let {
54
+ val locale: Locale = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
55
+ Resources .getSystem().configuration.locales.get(0 )
56
+ } else {
57
+ Resources .getSystem().configuration.locale
58
+ }
59
+ return java.lang.String .format(locale, it, * formatArgs)
60
+ }
61
+ return null
62
+ }
63
+
64
+ /* *
65
+ * Obfuscates the given value
66
+ * @param value
67
+ * @return String
68
+ */
69
+ @JvmStatic
70
+ fun obfuscateV2 (context : Context , value : String ): String? {
71
+ val bytes = Charset .forName(" UTF-8" ).encode(value)
72
+ val arrO = ByteArray (bytes.remaining())
73
+ bytes.get(arrO)
74
+ val arr: ByteArray = SC ().jniObfuscateV2(context, getCertificateSHA1Fingerprint(context), arrO)
75
+ return arr.map { it.toInt() }.toString().replace(" [" ," " ).replace(" ]" ," " )
76
+ }
77
+
78
+ /* *
79
+ * Reveals the given value
80
+ * @param id
81
+ * @return String
82
+ */
83
+ @JvmStatic
84
+ fun revealV2 (context : Context , @StringRes id : Int ): String? {
85
+ val arr: ByteArray = context.getString(id).split(" , " ).map { it.toInt().toByte() }.toByteArray()
86
+ return String (SC ().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr))
87
+ }
88
+
89
+ /* *
90
+ * Reveals the given value
91
+ * @param value
92
+ * @return String
93
+ */
94
+ @JvmStatic
95
+ fun revealV2 (context : Context , value : String ): String? {
96
+ val arr: ByteArray = value.split(" , " ).map { it.toInt().toByte() }.toByteArray()
97
+ return String (SC ().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr))
98
+ }
99
+
100
+ /* *
101
+ * Reveals the given value
102
+ * @param id
103
+ * @param formatArgs
104
+ * @return
105
+ */
106
+ @JvmStatic
107
+ fun revealV2 (context : Context , @StringRes id : Int , formatArgs : Array <out Any >): String? {
108
+ val value = revealV2(context, id)
109
+ value?.let {
110
+ val locale: Locale = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
111
+ Resources .getSystem().configuration.locales.get(0 )
112
+ } else {
113
+ Resources .getSystem().configuration.locale
114
+ }
115
+ return java.lang.String .format(locale, it, * formatArgs)
116
+ }
117
+ return null
118
+ }
119
+
120
+ }
121
+
122
+ }
0 commit comments