@@ -176,54 +176,39 @@ private static String byteArrayToHexString(byte[] bytes) {
176176 }
177177
178178 /**
179- * returns a decrypted value for the given string resource
180- * @param id
179+ * Obfuscates the given value
180+ * @param value
181181 * @return String
182182 */
183- @ Deprecated
184- public static String getString (@ StringRes int id ) {
183+ public static String obfuscate (String value ) {
185184 if (context == null ) {
186185 Log .e (TAG , "Library not initialized: SC.init(Context)" );
187186 return null ;
188187 }
189-
190- String hash = getCertificateSHA1Fingerprint ();
191188 try {
192- return decrypt (context . getString ( id ), hash );
189+ return jniObfuscate (context , getCertificateSHA1Fingerprint ( ), value );
193190 } catch (Exception e ) {
194191 e .printStackTrace ();
195192 }
196- return context .getString (id ); // returns original value, maybe not encrypted
197- }
198-
199- @ Deprecated
200- public static String getString (@ StringRes int id , Object ... formatArgs ) {
201- String value = getString (id );
202- Locale locale ;
203- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
204- locale = Resources .getSystem ().getConfiguration ().getLocales ().get (0 );
205- } else {
206- locale = Resources .getSystem ().getConfiguration ().locale ;
207- }
208- return String .format (locale , value , formatArgs );
193+ return value ;
209194 }
210195
211196 /**
212- * Obfuscates the given value
213- * @param value
197+ * Deobfuscates the given value
198+ * @param id
214199 * @return String
215200 */
216- public static String obfuscate ( String value ) {
201+ public static String deobfuscate ( @ StringRes int id ) {
217202 if (context == null ) {
218203 Log .e (TAG , "Library not initialized: SC.init(Context)" );
219204 return null ;
220205 }
221206 try {
222- return jniObfuscate (context , getCertificateSHA1Fingerprint (), value );
207+ return jniDeobfuscate (context , getCertificateSHA1Fingerprint (), context . getString ( id ) );
223208 } catch (Exception e ) {
224209 e .printStackTrace ();
225210 }
226- return "error" ;
211+ return context . getString ( id ) ;
227212 }
228213
229214 /**
@@ -241,7 +226,24 @@ public static String deobfuscate(String value) {
241226 } catch (Exception e ) {
242227 e .printStackTrace ();
243228 }
244- return "error" ;
229+ return value ;
230+ }
231+
232+ /**
233+ * Deobfuscates the given value
234+ * @param id
235+ * @param formatArgs
236+ * @return
237+ */
238+ public static String deobfuscate (@ StringRes int id , Object ... formatArgs ) {
239+ String value = deobfuscate (id );
240+ Locale locale ;
241+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
242+ locale = Resources .getSystem ().getConfiguration ().getLocales ().get (0 );
243+ } else {
244+ locale = Resources .getSystem ().getConfiguration ().locale ;
245+ }
246+ return String .format (locale , value , formatArgs );
245247 }
246248
247249 /**
@@ -267,7 +269,7 @@ public static String encryptString(String value) {
267269 }
268270
269271 /**
270- * Decrypts the given encrypted value
272+ * Decrypts the given value
271273 * @param value
272274 * @return String
273275 * @deprecated use {@link #deobfuscate(String)}()} instead.
@@ -288,4 +290,44 @@ public static String decryptString(String value) {
288290 return null ;
289291 }
290292
293+ /**
294+ * Decrypts the given ID
295+ * @param id
296+ * @return String
297+ */
298+ @ Deprecated
299+ public static String getString (@ StringRes int id ) {
300+ if (context == null ) {
301+ Log .e (TAG , "Library not initialized: SC.init(Context)" );
302+ return null ;
303+ }
304+
305+ String hash = getCertificateSHA1Fingerprint ();
306+ try {
307+ return decrypt (context .getString (id ), hash );
308+ } catch (Exception e ) {
309+ e .printStackTrace ();
310+ }
311+ return context .getString (id ); // returns original value, maybe not encrypted
312+ }
313+
314+ /**
315+ * Decrypts the given ID
316+ * @param id
317+ * @param formatArgs
318+ * @return String
319+ * @deprecated use {@link #deobfuscate(int, Object...)}()} instead.
320+ */
321+ @ Deprecated
322+ public static String getString (@ StringRes int id , Object ... formatArgs ) {
323+ String value = getString (id );
324+ Locale locale ;
325+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
326+ locale = Resources .getSystem ().getConfiguration ().getLocales ().get (0 );
327+ } else {
328+ locale = Resources .getSystem ().getConfiguration ().locale ;
329+ }
330+ return String .format (locale , value , formatArgs );
331+ }
332+
291333}
0 commit comments