-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClientUtils.java
More file actions
executable file
·85 lines (68 loc) · 2.62 KB
/
ClientUtils.java
File metadata and controls
executable file
·85 lines (68 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package vn.momo.momo_partner.Client;
/**
* Created By Bao.Nguyen on Sep 24, 2015
* Edited by Lanh.Luu,Hung.Do on 2/24/17.
* https://github.com/lanhmomo/MoMoPaySDK
*/
import android.app.Activity;
import android.content.SharedPreferences;
import android.util.Base64;
import org.apache.http.conn.util.InetAddressUtils;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import static android.content.Context.MODE_PRIVATE;
public class ClientUtils {
public ClientUtils() {
}
public static String getIPAddress(boolean useIPv4) {
try {
ArrayList ex = Collections.list(NetworkInterface.getNetworkInterfaces());
Iterator i$ = ex.iterator();
while(i$.hasNext()) {
NetworkInterface intf = (NetworkInterface)i$.next();
ArrayList addrs = Collections.list(intf.getInetAddresses());
Iterator i$1 = addrs.iterator();
while(i$1.hasNext()) {
InetAddress addr = (InetAddress)i$1.next();
if(!addr.isLoopbackAddress()) {
String sAddr = addr.getHostAddress().toUpperCase();
boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr);
if(useIPv4) {
if(isIPv4) {
return sAddr;
}
} else if(!isIPv4) {
int delim = sAddr.indexOf(37);
return delim < 0?sAddr:sAddr.substring(0, delim);
}
}
}
}
} catch (Exception var10) {
;
}
return "0.0.0.0";
}
public static void savePreferences(Activity context, String key, String value) {
SharedPreferences sp = context.getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString(key, value);
editor.commit();
}
public static String getPreferences(Activity context, String key) {
SharedPreferences sp = context.getPreferences(MODE_PRIVATE);
return sp.getString(key,"");
}
}