diff --git a/app/src/main/java/com/zcshou/utils/AESUtils.java b/app/src/main/java/com/zcshou/utils/AESUtils.java deleted file mode 100644 index 332584a..0000000 --- a/app/src/main/java/com/zcshou/utils/AESUtils.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.zcshou.utils; - -import org.jetbrains.annotations.NotNull; - -import javax.crypto.Cipher; -import javax.crypto.spec.SecretKeySpec; - -import java.nio.charset.StandardCharsets; -import java.util.Random; - - -public class AESUtils { - /* AES秘钥支持128bit/192bit/256bit三种长度的秘钥,一个字节等于8bit, - * 因此支持生成的字符串的长度应该是 16/24/32 - * */ - - // 16 字节 AES秘钥长度(128bit) - public static final int KEY_LENGTH_16 = 16; - // 24 字节 AES秘钥长度(192bit) - public static final int KEY_LENGTH_24 = 24; - // 32 字节 AES秘钥长度(256bit) - public static final int KEY_LENGTH_32 = 32; - - // 实际上,“ RSA / ECB / PKCS1Padding”未实现ECB模式加密。 它应该被称为“ RSA / None / PKCS1Padding”, - // 因为它只能用于加密单个明文块(或者实际上是一个秘密密钥)。 这只是Sun / Oracle的命名错误。 - private static final String cipherMode = "AES/None/PKCS5Padding";//算法/模式/补码方式 - - -// public static void main(String[] args) { -// -// /*构建一个随机密码*/ -// String key = getRandomKey(24); -// System.out.println("随机生成的key:" + key); -// -// String data = "{'fig':1,'message':'登录成功'}"; -// -// try { -// String encriptData = AESUtils.encrypt(data, key); -// System.out.println("加密后的数据:" + encriptData); -// -// String decryptData = decrypt(encriptData, key); -// -// System.out.println("解密后的数据:" + decryptData); -// -// } catch (Exception e) { -// e.printStackTrace(); -// } -// -// } - - - /** - * @param length 需要生成的字符串长度 - * @return 随机生成的字符串 - */ - public static String getRandomKey(int length) { - - if (length != KEY_LENGTH_16 && length != KEY_LENGTH_24 && length != KEY_LENGTH_32) { - System.out.println("长度必须为16/24/32"); - return null; - } - - String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - Random random = new Random(); - StringBuilder stringBuilder = new StringBuilder(); - for (int i = 0; i < length; i++) { - int number = random.nextInt(62); - stringBuilder.append(str.charAt(number)); - } - return stringBuilder.toString(); - - } - - - /** - * @param data 需要加密的数据 - * @param key 加密使用的key - * @return 加密后的数据(Base64编码) - * @throws Exception 异常 - */ - public static String encrypt(String data, @NotNull String key) throws Exception { - - int length = key.length(); - if (length != KEY_LENGTH_16 && length != KEY_LENGTH_24 && length != KEY_LENGTH_32) { - System.out.println("长度必须为16/24/32"); - return null; - } - - byte[] raw = key.getBytes(StandardCharsets.UTF_8); - SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); - Cipher cipher = Cipher.getInstance(cipherMode); - cipher.init(Cipher.ENCRYPT_MODE, skeySpec); - byte[] encrypted = cipher.doFinal(data.getBytes(StandardCharsets.UTF_8)); - - return Base64.encode(encrypted); - } - - - /** - * @param data 需要解密的数据 - * @param key 解密用的key - * @return 解密后的数据 - */ - public static String decrypt(String data, @NotNull String key) { - try { - int length = key.length(); - if (length != KEY_LENGTH_16 && length != KEY_LENGTH_24 && length != KEY_LENGTH_32) { - System.out.println("长度必须为16/24/32"); - return null; - } - - byte[] raw = key.getBytes(StandardCharsets.UTF_8); - SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); - Cipher cipher = Cipher.getInstance(cipherMode); - cipher.init(Cipher.DECRYPT_MODE, skeySpec); - byte[] encrypted = Base64.decode(data);//先用base64解密 - try { - byte[] original = cipher.doFinal(encrypted); - return new String(original, StandardCharsets.UTF_8); - } catch (Exception e) { - System.out.println(e.toString()); - return null; - } - } catch (Exception ex) { - System.out.println(ex.toString()); - return null; - } - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/zcshou/utils/Base64.java b/app/src/main/java/com/zcshou/utils/Base64.java deleted file mode 100644 index 42699fc..0000000 --- a/app/src/main/java/com/zcshou/utils/Base64.java +++ /dev/null @@ -1,268 +0,0 @@ -package com.zcshou.utils; - -public final class Base64 { - - private static final int BASELENGTH = 128; - private static final int LOOKUPLENGTH = 64; - private static final int TWENTYFOURBITGROUP = 24; - private static final int EIGHTBIT = 8; - private static final int SIXTEENBIT = 16; - private static final int FOURBYTE = 4; - private static final int SIGN = -128; - private static char PAD = '='; - private static byte[] base64Alphabet = new byte[BASELENGTH]; - private static char[] lookUpBase64Alphabet = new char[LOOKUPLENGTH]; - - static { - for (int i = 0; i < BASELENGTH; ++i) { - base64Alphabet[i] = -1; - } - for (int i = 'Z'; i >= 'A'; i--) { - base64Alphabet[i] = (byte) (i - 'A'); - } - for (int i = 'z'; i >= 'a'; i--) { - base64Alphabet[i] = (byte) (i - 'a' + 26); - } - - for (int i = '9'; i >= '0'; i--) { - base64Alphabet[i] = (byte) (i - '0' + 52); - } - - base64Alphabet['+'] = 62; - base64Alphabet['/'] = 63; - - for (int i = 0; i <= 25; i++) { - lookUpBase64Alphabet[i] = (char) ('A' + i); - } - - for (int i = 26, j = 0; i <= 51; i++, j++) { - lookUpBase64Alphabet[i] = (char) ('a' + j); - } - - for (int i = 52, j = 0; i <= 61; i++, j++) { - lookUpBase64Alphabet[i] = (char) ('0' + j); - } - lookUpBase64Alphabet[62] = (char) '+'; - lookUpBase64Alphabet[63] = (char) '/'; - - } - - private static boolean isWhiteSpace(char octect) { - return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9); - } - - private static boolean isPad(char octect) { - return (octect == PAD); - } - - private static boolean isData(char octect) { - return (octect < BASELENGTH && base64Alphabet[octect] != -1); - } - - /** - * Encodes hex octects into Base64 - * - * @param binaryData - * Array containing binaryData - * @return Encoded Base64 array - */ - public static String encode(byte[] binaryData) { - - if (binaryData == null) { - return null; - } - - int lengthDataBits = binaryData.length * EIGHTBIT; - if (lengthDataBits == 0) { - return ""; - } - - int fewerThan24bits = lengthDataBits % TWENTYFOURBITGROUP; - int numberTriplets = lengthDataBits / TWENTYFOURBITGROUP; - int numberQuartet = fewerThan24bits != 0 ? numberTriplets + 1 - : numberTriplets; - char encodedData[] = null; - - encodedData = new char[numberQuartet * 4]; - - byte k = 0, l = 0, b1 = 0, b2 = 0, b3 = 0; - - int encodedIndex = 0; - int dataIndex = 0; - - for (int i = 0; i < numberTriplets; i++) { - b1 = binaryData[dataIndex++]; - b2 = binaryData[dataIndex++]; - b3 = binaryData[dataIndex++]; - - l = (byte) (b2 & 0x0f); - k = (byte) (b1 & 0x03); - - byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) - : (byte) ((b1) >> 2 ^ 0xc0); - byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) - : (byte) ((b2) >> 4 ^ 0xf0); - byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) - : (byte) ((b3) >> 6 ^ 0xfc); - - encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[(l << 2) | val3]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[b3 & 0x3f]; - } - - // form integral number of 6-bit groups - if (fewerThan24bits == EIGHTBIT) { - b1 = binaryData[dataIndex]; - k = (byte) (b1 & 0x03); - - byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) - : (byte) ((b1) >> 2 ^ 0xc0); - encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[k << 4]; - encodedData[encodedIndex++] = PAD; - encodedData[encodedIndex++] = PAD; - } else if (fewerThan24bits == SIXTEENBIT) { - b1 = binaryData[dataIndex]; - b2 = binaryData[dataIndex + 1]; - l = (byte) (b2 & 0x0f); - k = (byte) (b1 & 0x03); - - byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) - : (byte) ((b1) >> 2 ^ 0xc0); - byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) - : (byte) ((b2) >> 4 ^ 0xf0); - - encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[l << 2]; - encodedData[encodedIndex++] = PAD; - } - - return new String(encodedData); - } - - /** - * Decodes Base64 data into octects - * - * @param encoded - * string containing Base64 data - * @return Array containind decoded data. - */ - public static byte[] decode(String encoded) { - - if (encoded == null) { - return null; - } - - char[] base64Data = encoded.toCharArray(); - // remove white spaces - int len = removeWhiteSpace(base64Data); - - if (len % FOURBYTE != 0) { - return null;// should be divisible by four - } - - int numberQuadruple = (len / FOURBYTE); - - if (numberQuadruple == 0) { - return new byte[0]; - } - - byte decodedData[] = null; - byte b1 = 0, b2 = 0, b3 = 0, b4 = 0; - char d1 = 0, d2 = 0, d3 = 0, d4 = 0; - - int i = 0; - int encodedIndex = 0; - int dataIndex = 0; - decodedData = new byte[(numberQuadruple) * 3]; - - for (; i < numberQuadruple - 1; i++) { - - if (!isData((d1 = base64Data[dataIndex++])) - || !isData((d2 = base64Data[dataIndex++])) - || !isData((d3 = base64Data[dataIndex++])) - || !isData((d4 = base64Data[dataIndex++]))) { - return null; - }// if found "no data" just return null - - b1 = base64Alphabet[d1]; - b2 = base64Alphabet[d2]; - b3 = base64Alphabet[d3]; - b4 = base64Alphabet[d4]; - - decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); - decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); - decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); - } - - if (!isData((d1 = base64Data[dataIndex++])) - || !isData((d2 = base64Data[dataIndex++]))) { - return null;// if found "no data" just return null - } - - b1 = base64Alphabet[d1]; - b2 = base64Alphabet[d2]; - - d3 = base64Data[dataIndex++]; - d4 = base64Data[dataIndex++]; - if (!isData((d3)) || !isData((d4))) {// Check if they are PAD characters - if (isPad(d3) && isPad(d4)) { - if ((b2 & 0xf) != 0)// last 4 bits should be zero - { - return null; - } - byte[] tmp = new byte[i * 3 + 1]; - System.arraycopy(decodedData, 0, tmp, 0, i * 3); - tmp[encodedIndex] = (byte) (b1 << 2 | b2 >> 4); - return tmp; - } else if (!isPad(d3) && isPad(d4)) { - b3 = base64Alphabet[d3]; - if ((b3 & 0x3) != 0)// last 2 bits should be zero - { - return null; - } - byte[] tmp = new byte[i * 3 + 2]; - System.arraycopy(decodedData, 0, tmp, 0, i * 3); - tmp[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); - tmp[encodedIndex] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); - return tmp; - } else { - return null; - } - } else { // No PAD e.g 3cQl - b3 = base64Alphabet[d3]; - b4 = base64Alphabet[d4]; - decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); - decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); - decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); - - } - - return decodedData; - } - - /** - * remove WhiteSpace from MIME containing encoded Base64 data. - * - * @param data - * the byte array of base64 data (with WS) - * @return the new length - */ - private static int removeWhiteSpace(char[] data) { - if (data == null) { - return 0; - } - - // count characters that's not whitespace - int newSize = 0; - int len = data.length; - for (int i = 0; i < len; i++) { - if (!isWhiteSpace(data[i])) { - data[newSize++] = data[i]; - } - } - return newSize; - } -} diff --git a/app/src/main/java/com/zcshou/utils/DeviceIdUtils.java b/app/src/main/java/com/zcshou/utils/DeviceIdUtils.java deleted file mode 100644 index 42f5683..0000000 --- a/app/src/main/java/com/zcshou/utils/DeviceIdUtils.java +++ /dev/null @@ -1,183 +0,0 @@ -package com.zcshou.utils; - -import android.content.Context; -import android.os.Build; -import android.provider.Settings; -import android.telephony.TelephonyManager; - -import androidx.annotation.RequiresApi; - -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.util.Locale; -import java.util.UUID; - -public class DeviceIdUtils { - /** - * 获得设备硬件标识 - * - * @param context 上下文 - * @return 设备硬件标识 - */ - @RequiresApi(api = Build.VERSION_CODES.O) - public static String getDeviceId(Context context) { - StringBuilder sbDeviceId = new StringBuilder(); - - //获得设备默认IMEI(>=6.0 需要ReadPhoneState权限) - - String imei = getIMEI(context); - - //获得AndroidId(无需权限) - String androidid = getAndroidId(context); - - //获得设备序列号(无需权限) - String serial = getSERIAL(); - - //获得硬件uuid(根据硬件相关属性,生成uuid)(无需权限) - String uuid = getDeviceUUID().replace("-", ""); - - //追加 imei - if (imei != null && imei.length() > 0) { - sbDeviceId.append(imei); - sbDeviceId.append("|"); - } - //追加 androidid - if (androidid != null && androidid.length() > 0) { - sbDeviceId.append(androidid); - sbDeviceId.append("|"); - } - - //追加serial - if (serial != null && serial.length() > 0) { - sbDeviceId.append(serial); - sbDeviceId.append("|"); - } - - //追加硬件uuid - if (uuid != null && uuid.length() > 0) { - sbDeviceId.append(uuid); - } - - //生成SHA1,统一DeviceId长度 - if (sbDeviceId.length() > 0) { - try { - byte[] hash = getHashByString(sbDeviceId.toString()); - String sha1 = bytesToHex(hash); - if (sha1 != null && sha1.length() > 0) { - //返回最终的DeviceId - return sha1; - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - //如果以上硬件标识数据均无法获得, - //则DeviceId默认使用系统随机数,这样保证DeviceId不为空 - return UUID.randomUUID().toString().replace("-", ""); - } - - //需要获得READ_PHONE_STATE权限,>=6.0,默认返回null - @RequiresApi(api = Build.VERSION_CODES.O) - private static String getIMEI(Context context) { - try { - TelephonyManager tm = (TelephonyManager) - context.getSystemService(Context.TELEPHONY_SERVICE); - return tm.getImei(); - } catch (Exception ex) { - ex.printStackTrace(); - } - return ""; - } - - /** - * 获得设备的AndroidId - * - * @param context 上下文 - * @return 设备的AndroidId - */ - private static String getAndroidId(Context context) { - try { - return Settings.Secure.getString(context.getContentResolver(), - Settings.Secure.ANDROID_ID); - } catch (Exception ex) { - ex.printStackTrace(); - } - return ""; - } - - /** - * 获得设备序列号(如:WTK7N16923005607), 个别设备无法获取 - * - * @return 设备序列号 - */ - private static String getSERIAL() { - String serial =""; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - serial = Build.getSerial(); - } else { - serial = Build.SERIAL; - } - return serial; - } - - /** - * 获得设备硬件uuid - * 使用硬件信息,计算出一个随机数 - * - * @return 设备硬件uuid - */ - @RequiresApi(api = Build.VERSION_CODES.O) - private static String getDeviceUUID() { - try { - String dev = "3883756" + - Build.BOARD.length() % 10 + - Build.BRAND.length() % 10 + - Build.DEVICE.length() % 10 + - Build.HARDWARE.length() % 10 + - Build.ID.length() % 10 + - Build.MODEL.length() % 10 + - Build.PRODUCT.length() % 10 + - Build.getSerial().length() % 10; - return new UUID(dev.hashCode(), - Build.getSerial().hashCode()).toString(); - } catch (Exception ex) { - ex.printStackTrace(); - return ""; - } - } - - /** - * 取SHA1 - * @param data 数据 - * @return 对应的hash值 - */ - private static byte[] getHashByString(String data) { - try { - MessageDigest messageDigest = MessageDigest.getInstance("SHA1"); - messageDigest.reset(); - messageDigest.update(data.getBytes(StandardCharsets.UTF_8)); - return messageDigest.digest(); - } catch (Exception e){ - return "".getBytes(); - } - } - - /** - * 转16进制字符串 - * @param data 数据 - * @return 16进制字符串 - */ - private static String bytesToHex(byte[] data) { - StringBuilder sb = new StringBuilder(); - String stmp; - for (byte datum : data) { - stmp = (Integer.toHexString(datum & 0xFF)); - if (stmp.length() == 1) - sb.append("0"); - sb.append(stmp); - } - return sb.toString().toUpperCase(Locale.CHINA); - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/zcshou/utils/RSAUtils.java b/app/src/main/java/com/zcshou/utils/RSAUtils.java deleted file mode 100644 index 06ea421..0000000 --- a/app/src/main/java/com/zcshou/utils/RSAUtils.java +++ /dev/null @@ -1,351 +0,0 @@ -package com.zcshou.utils; - - -import javax.crypto.Cipher; -import java.io.ByteArrayOutputStream; -import java.security.*; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; -import java.security.spec.PKCS8EncodedKeySpec; -import java.security.spec.X509EncodedKeySpec; -import java.util.HashMap; -import java.util.Map; - - -public class RSAUtils { - public static final int KEY_LENGTH_1024 = 1024; - - public static final int KEY_LENGTH_2048 = 2048; - - /** - * 加密算法RSA - */ - private static final String KEY_ALGORITHM = "RSA"; - - /** - * 签名算法 - */ - // public static final String SIGNATURE_ALGORITHM = "MD5withRSA"; - private static final String SIGNATURE_ALGORITHM = "SHA256withRSA"; - - /** - * 获取公钥的key - */ - private static final String PUBLIC_KEY = "RSAPublicKey"; - - - /** - * 获取私钥的key - */ - private static final String PRIVATE_KEY = "RSAPrivateKey"; - - - /** - * RSA最大加密明文大小 - */ - private static final int MAX_ENCRYPT_BLOCK = 117; - - - /** - * RSA最大解密密文大小 - */ - private static final int MAX_DECRYPT_BLOCK = 256; - - -// public static void main(String[] args) { -// -// -// /*RSA 1024 */ -//// String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCIarYvrIMZGHKa8f2E6ubg0//28R1zJ4ArD+XELXYvDrM8UBR42PqJCpjPN3hC91YAnnk2Y9U+X5o/rGxH5ZTZzYy+rkAmZFJa1fK2mWDxPYJoxH+DGHQc+h8t83BMB4pKqVPhcJVF6Ie+qpD5RFUU/e5iEz8ZZFDroVE3ubKaKwIDAQAB"; -//// String privateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAIhqti+sgxkYcprx/YTq5uDT//bxHXMngCsP5cQtdi8OszxQFHjY+okKmM83eEL3VgCeeTZj1T5fmj+sbEfllNnNjL6uQCZkUlrV8raZYPE9gmjEf4MYdBz6Hy3zcEwHikqpU+FwlUXoh76qkPlEVRT97mITPxlkUOuhUTe5sporAgMBAAECgYA0aSND37iifKUTaKOpXIKFoI23910EMAnrAXmaTIkafUBZjL7Ay0Q+QIcDHeGjgNlW9YvGXMbB5wMhMYKMgOUV1FpeqQdDslO4Z7zynRjkDJkjOKkE2/j10CvmNO8e2uCWKsYYUE9IyTkxcypjBCv16ifT0qmdxb7uKLccYI16eQJBANMutfNO/q7kUKiYvilBLN9+pZOg6eTmKmV0Xygoa3ClpQTfurwLA8W/Fv3oXnjHXTryNVHeoxSH69imo0RZ9kcCQQClXhMbXlfvl5iInmwziFhtYBztvkLuyQ084FgszR7iR0nuOWoURLQa5O7sLL724FNRlSvOCmmmWguh2vmQgRr9AkBDS5tHkWCvMqpRT3spgk9eWOlChgCCpKXV9qNsFJVILEDNsM28pnXpSd91wdp4+m7HHe/Hyv6EyFtrio50dYZ5AkAODVVwUO8GBArJKTUml+JzwOQUa8OCSQFf9+xmOjPypH4qySQzfrcTRfrrhM3haqSJ3TQwuP/LTAGLCnGEjwP9AkBqFFyrrQviPOhwel3NWjRv8mftOFgnm0Isk/NQJ4JtoahYvPDeUyP80WSuVWnPyV4zHz9Kw7BggYCPc4xZDACV"; -// -// -// /*RSA 2048*/ -// -// String publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAichGTEP0QFswnvn+ZAQrgGHM8VeDZLJuezGhgxh4d9SyRUfnIW/zefT71rwS4bZUs1MPxJwavOyxABJOHLuckdHXknCsGEWz78gsA6D0+O+9dl1gCZR29nnN/NlzmNbSjFnzvsTJYBlS88qSr35RXFE+6DM7uPsS8Fm2I+65FteJ8p2yMvpSg72QkIX8xvI1F1uwXrciIB+4u7uTozxIplMOo4a6uhAm3W+Kjpz3ni2btjGqHRbqb3ebSZyl+nFfnjQaBe3XyVxAWDSanjgFj/wbqbeug9FBs+nQFVPIZR9z0aE5Ndi5o3eSkV7HFmWpkxaiPZ0BLRK3XHMaBtuSpwIDAQAB"; -// String privateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCJyEZMQ/RAWzCe+f5kBCuAYczxV4Nksm57MaGDGHh31LJFR+chb/N59PvWvBLhtlSzUw/EnBq87LEAEk4cu5yR0deScKwYRbPvyCwDoPT47712XWAJlHb2ec382XOY1tKMWfO+xMlgGVLzypKvflFcUT7oMzu4+xLwWbYj7rkW14nynbIy+lKDvZCQhfzG8jUXW7BetyIgH7i7u5OjPEimUw6jhrq6ECbdb4qOnPeeLZu2MaodFupvd5tJnKX6cV+eNBoF7dfJXEBYNJqeOAWP/Bupt66D0UGz6dAVU8hlH3PRoTk12Lmjd5KRXscWZamTFqI9nQEtErdccxoG25KnAgMBAAECggEBAIPz1b88ZTMtIgdejA7lH3Q4Nbn8gc1yRPSet3uBd/3rKT/IeMZBHQBzaqxgOgUIRV3n8nXsun6sf2b+IOjLlErimH2agnZMauL85YokH/g4QU6WZl9GXBf41xmMd3SsZ8AadaEBfYoXNqZcHtcLNogfFwvx5QRnD+A3SoRnH8OLBeVvOEe4AqHLT2xEZ9TeCf3fJe0Rf0fUIbw7I5ioiRZV/ir0L1VM7+1k2JODUkdC2Luj5Tl3nl1Eg6EmkYCmGE1bip1NAatsfjPBLMF7XdPNjLboiffjgKVBOjb7Y9vL18BCoLtWeTT2GkMpi5Sr94T1te1Ox77dF4BP33Xn7eECgYEA1TNUrAQsh14NbbkwFtUHXS8/YXt81p9wbSpFBymIawF2Lkk0913TB4CHSun45LhYXjdZZxK/TgqC5EIq5v2RA0jY3cSxoqVe6RZKB04E8wszeJHiEJPdu2vFnpZh9iAyhswiM5FmuKZKoWsVc2SZrBXAI02smSn3lXYok1VBS3sCgYEApXEZS6gjUu4o7ZL53Ur1HDfi/nxpkxqrPh+D1HVYjzjT+4vTeZwtLXt2VCInPWNXH+f11mzhxIrLkI0jMcSCah81DuU8aFXnqvPuyFvt9uaQBYlVWBtkcGZyeaxHFrbfCyeu0jm7SfwmiIg12hKlIHtPTjEZQUX+kkWr8cdaZ8UCgYEAh0Pl+K09QzVc97yC0jmeTnTnlYWvksvdnKUw3nZvYtSukndH75nLhfr524HOs+5xwnUDd+3hCjaJDSEd7yf5lUfmr+1XdoXNTb0igrfxU/JLWbfU4geuqnaaDyACTxHmfLePC4C413ZJ61fxaCDvjsrN+JgTZanGt0EcRT3WC3kCgYEAgf5/GMJxlw0JXbs515a5R8Xl9358Whj/at3KcRsPTeIiNqnkrc54dR9ol60KViMDZ0+VDDobn5pLXzZ26/jzXD1PLHgU4gp18Q6glhAdx/3cNm11gLhtUCA/XLlwVjm0wggZRpgUQIr/IBKe9c3mr8IUS2Uq6e38nKRf+adhst0CgYAM4tvl+U1MPbbz3YzDv8QPepZ7Pglgdfxqfr5OkXA7jNhqTZjSq10B6oClGvirBo1m6f26F02iUKk1n67AuiLlTP/RRZHi1cfq6P9IaXl23PcxJfUMvIxQDS0U+UTFpNXryTw/qNAkSfufN48YzKdGvc8vHrYJyaeemaVlbdJOCw=="; -// -// -// try { -// -// String data = "测试提交数据"; -// -// byte[] publicEncryptBytes = RSAUtils.encryptByPublicKey(data.getBytes(), publicKey); -// System.out.println("公钥加密后的数据:" + Base64.encode(publicEncryptBytes)); -// byte[] privatDecryptBytes = RSAUtils.decryptByPrivateKey(publicEncryptBytes, privateKey); -// System.out.println("私钥解密后的数据:" + new String(privatDecryptBytes)); -// -// -// System.out.println("--------------------"); -// -// byte[] privateKeyEncryptBytes = RSAUtils.encryptByPrivateKey(data.getBytes(), privateKey); -// System.out.println("私钥加密后的数据:" + Base64.encode(privateKeyEncryptBytes)); -// -// String singnData = RSAUtils.sign(data.getBytes(), privateKey); -// System.out.println("私钥签名后的数据:" + singnData); -// -// -// byte[] publicDecryptBytes = RSAUtils.decryptByPublicKey(privateKeyEncryptBytes, publicKey); -// System.out.println("公钥解密后的数据:" + new String(publicDecryptBytes)); -// -// boolean isSign = RSAUtils.verify(data.getBytes(), publicKey, singnData); -// System.out.println("签名是否正确:" + isSign); -// -// -// } catch (Exception e) { -// e.printStackTrace(); -// } -// } - - - /** - * @param keySize 生成的秘钥长度 一般为1024或2048 - * @return - * * @throws Exception 异常 - */ - public static Map genKeyPair(int keySize) throws Exception { - if (keySize != KEY_LENGTH_1024 && keySize != KEY_LENGTH_2048) { - return null; - } - KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM); - keyPairGen.initialize(keySize); - KeyPair keyPair = keyPairGen.generateKeyPair(); - RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); - RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate(); - Map keyMap = new HashMap<>(2); - keyMap.put(PUBLIC_KEY, publicKey); - keyMap.put(PRIVATE_KEY, privateKey); - - System.out.println("publicKey:" + Base64.encode(publicKey.getEncoded())); - System.out.println("privateKey:" + Base64.encode(privateKey.getEncoded())); - - return keyMap; - } - - - /** - * 对已加密数据进行签名 - * - * @param data 已加密的数据 - * @param privateKey 私钥 - * @return 对已加密数据生成的签名 - * * @throws Exception 异常 - */ - - public static String sign(byte[] data, String privateKey) throws Exception { - byte[] keyBytes = Base64.decode(privateKey); - PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes); - KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); - PrivateKey privateK = keyFactory.generatePrivate(pkcs8KeySpec); - Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM); - signature.initSign(privateK); - signature.update(data); - return Base64.encode(signature.sign()); - } - - - /** - * 验签 - * - * @param data 签名之前的数据 - * @param publicKey 公钥 - * @param sign 签名之后的数据 - * @return 验签是否成功 - * * @throws Exception 异常 - */ - public static boolean verify(byte[] data, String publicKey, String sign) throws Exception { - byte[] keyBytes = Base64.decode(publicKey); - X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); - KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); - PublicKey publicK = keyFactory.generatePublic(keySpec); - Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM); - signature.initVerify(publicK); - signature.update(data); - return signature.verify(Base64.decode(sign)); - } - - - /** - * 用私钥对数据进行解密 - * - * @param encryptedData 使用公钥加密过的数据 - * @param privateKey 私钥 - * @return 解密后的数据 - * * @throws Exception 异常 - */ - public static byte[] decryptByPrivateKey(byte[] encryptedData, String privateKey) throws Exception { - byte[] keyBytes = Base64.decode(privateKey); - PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes); - KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); - Key privateK = keyFactory.generatePrivate(pkcs8KeySpec); - //Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); - Cipher cipher = Cipher.getInstance(KEY_ALGORITHM); - cipher.init(Cipher.DECRYPT_MODE, privateK); - - int inputLen = encryptedData.length; - ByteArrayOutputStream out = new ByteArrayOutputStream(); - int offSet = 0; - byte[] cache; - int i = 0; - // 对数据分段解密 - while (inputLen - offSet > 0) { - if (inputLen - offSet > MAX_DECRYPT_BLOCK) { - cache = cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK); - } else { - cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet); - } - out.write(cache, 0, cache.length); - i++; - offSet = i * MAX_DECRYPT_BLOCK; - } - byte[] decryptedData = out.toByteArray(); - out.close(); - - - return decryptedData; - } - - /** - * 公钥解密 - * - * @param encryptedData 使用私钥加密过的数据 - * @param publicKey 公钥 - * @return 解密后的数据 - * * @throws Exception 异常 - */ - public static byte[] decryptByPublicKey(byte[] encryptedData, String publicKey) throws Exception { - byte[] keyBytes = Base64.decode(publicKey); - X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes); - KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); - Key publicK = keyFactory.generatePublic(x509KeySpec); - Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); - cipher.init(Cipher.DECRYPT_MODE, publicK); - int inputLen = encryptedData.length; - ByteArrayOutputStream out = new ByteArrayOutputStream(); - int offSet = 0; - byte[] cache; - int i = 0; - // 对数据分段解密 - while (inputLen - offSet > 0) { - if (inputLen - offSet > MAX_DECRYPT_BLOCK) { - cache = cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK); - } else { - cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet); - } - out.write(cache, 0, cache.length); - i++; - offSet = i * MAX_DECRYPT_BLOCK; - } - byte[] decryptedData = out.toByteArray(); - out.close(); - return decryptedData; - } - - - /** - * 公钥加密 - * - * @param data 需要加密的数据 - * @param publicKey 公钥 - * @return 使用公钥加密后的数据 - * * @throws Exception 异常 - */ - public static byte[] encryptByPublicKey(byte[] data, String publicKey) throws Exception { - byte[] keyBytes = Base64.decode(publicKey); - X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes); - KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); - Key publicK = keyFactory.generatePublic(x509KeySpec); - // 对数据加密 - Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); - cipher.init(Cipher.ENCRYPT_MODE, publicK); - int inputLen = data.length; - ByteArrayOutputStream out = new ByteArrayOutputStream(); - int offSet = 0; - byte[] cache; - int i = 0; - // 对数据分段加密 - while (inputLen - offSet > 0) { - if (inputLen - offSet > MAX_ENCRYPT_BLOCK) { - cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK); - } else { - cache = cipher.doFinal(data, offSet, inputLen - offSet); - } - out.write(cache, 0, cache.length); - i++; - offSet = i * MAX_ENCRYPT_BLOCK; - } - byte[] encryptedData = out.toByteArray(); - out.close(); - return encryptedData; - } - - - /** - * 私钥加密 - * - * @param data 待加密的数据 - * @param privateKey 私钥 - * @return 使用私钥加密后的数据 - * * @throws Exception 异常 - */ - public static byte[] encryptByPrivateKey(byte[] data, String privateKey) throws Exception { - byte[] keyBytes = Base64.decode(privateKey); - PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes); - KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); - Key privateK = keyFactory.generatePrivate(pkcs8KeySpec); - Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); - cipher.init(Cipher.ENCRYPT_MODE, privateK); - int inputLen = data.length; - ByteArrayOutputStream out = new ByteArrayOutputStream(); - int offSet = 0; - byte[] cache; - int i = 0; - // 对数据分段加密 - while (inputLen - offSet > 0) { - if (inputLen - offSet > MAX_ENCRYPT_BLOCK) { - cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK); - } else { - cache = cipher.doFinal(data, offSet, inputLen - offSet); - } - out.write(cache, 0, cache.length); - i++; - offSet = i * MAX_ENCRYPT_BLOCK; - } - byte[] encryptedData = out.toByteArray(); - out.close(); - return encryptedData; - } - - - /** - * 获取私钥 - * - * @param keyMap 生成的秘钥对 - * @return 私钥 - */ - public static String getPrivateKey(Map keyMap) { - Key key = (Key) keyMap.get(PRIVATE_KEY); - if (key == null) { - return null; - } else { - return Base64.encode(key.getEncoded()); - } - } - - - /** - * 获取公钥 - * - * @param keyMap 生成的秘钥对 - * @return 公钥 - */ - public static String getPublicKey(Map keyMap) { - Key key = (Key) keyMap.get(PUBLIC_KEY); - if (key == null) { - return null; - } else { - return Base64.encode(key.getEncoded()); - } - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/zcshou/utils/RomUtils.java b/app/src/main/java/com/zcshou/utils/RomUtils.java deleted file mode 100644 index cc7995a..0000000 --- a/app/src/main/java/com/zcshou/utils/RomUtils.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.zcshou.utils; - -import android.os.Build; -import android.text.TextUtils; -import android.util.Log; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; - -/** - * Created by HaiyuKing - * Used 判断手机ROM,检测ROM是MIUI、EMUI还是Flyme - * 参考资料:https://www.jianshu.com/p/ba9347a5a05a - */ -public class RomUtils { - private static final String TAG = "Rom"; - - public static final String ROM_MIUI = "MIUI"; - public static final String ROM_EMUI = "EMUI"; - public static final String ROM_FLYME = "FLYME"; - public static final String ROM_OPPO = "OPPO"; - public static final String ROM_SMARTISAN = "SMARTISAN"; - public static final String ROM_VIVO = "VIVO"; - public static final String ROM_QIKU = "QIKU"; - - private static final String KEY_VERSION_MIUI = "ro.miui.ui.version.name"; - private static final String KEY_VERSION_EMUI = "ro.build.version.emui"; - private static final String KEY_VERSION_OPPO = "ro.build.version.opporom"; - private static final String KEY_VERSION_SMARTISAN = "ro.smartisan.version"; - private static final String KEY_VERSION_VIVO = "ro.vivo.os.version"; - - private static String sName; - private static String sVersion; - - //华为 - public static boolean isEmui() { - return check(ROM_EMUI); - } - //小米 - public static boolean isMiui() { - return check(ROM_MIUI); - } - //vivo - public static boolean isVivo() { - return check(ROM_VIVO); - } - //oppo - public static boolean isOppo() { - return check(ROM_OPPO); - } - //魅族 - public static boolean isFlyme() { - return check(ROM_FLYME); - } - //360手机 - public static boolean is360() { - return check(ROM_QIKU) || check("360"); - } - - public static boolean isSmartisan() { - return check(ROM_SMARTISAN); - } - - public static String getName() { - if (sName == null) { - check(""); - } - return sName; - } - - public static String getVersion() { - if (sVersion == null) { - check(""); - } - return sVersion; - } - - public static boolean check(String rom) { - if (sName != null) { - return sName.equals(rom); - } - - if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_MIUI))) { - sName = ROM_MIUI; - } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_EMUI))) { - sName = ROM_EMUI; - } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_OPPO))) { - sName = ROM_OPPO; - } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_VIVO))) { - sName = ROM_VIVO; - } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_SMARTISAN))) { - sName = ROM_SMARTISAN; - } else { - sVersion = Build.DISPLAY; - if (sVersion.toUpperCase().contains(ROM_FLYME)) { - sName = ROM_FLYME; - } else { - sVersion = Build.UNKNOWN; - sName = Build.MANUFACTURER.toUpperCase(); - } - } - return sName.equals(rom); - } - - public static String getProp(String name) { - String line = null; - BufferedReader input = null; - try { - Process p = Runtime.getRuntime().exec("getprop " + name); - input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024); - line = input.readLine(); - input.close(); - } catch (IOException ex) { - Log.e(TAG, "Unable to read prop " + name, ex); - return null; - } finally { - if (input != null) { - try { - input.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - return line; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/zcshou/utils/TimeUtils.java b/app/src/main/java/com/zcshou/utils/TimeUtils.java deleted file mode 100644 index 9321a5a..0000000 --- a/app/src/main/java/com/zcshou/utils/TimeUtils.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.zcshou.utils; - -import android.util.Log; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; - -public class TimeUtils { - /** - * 获取当前时间 - * - * @return string - */ - public static String getNowTime() { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); - Date date = new Date(System.currentTimeMillis()); - return simpleDateFormat.format(date); - } - - /** - * 获取时间戳 - * - * @return 获取时间戳 - */ - public static String getTimeString() { - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); - Calendar calendar = Calendar.getInstance(); - return df.format(calendar.getTime()); - } - - /** - * 时间转换为时间戳 - * - * @param time:需要转换的时间 - * @return string - */ - public static String dateToStamp(String time) { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); - Date date = null; - try { - date = simpleDateFormat.parse(time); - } catch (ParseException e) { - e.printStackTrace(); - } - if (date == null) { - return null; - } else { - long ts = date.getTime(); - return String.valueOf(ts); - } - } - - /** - * 时间戳转换为字符串 - * - * @param time:时间戳 - * @return string - */ - public static String times(String time) { - SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd HH时mm分", Locale.getDefault()); - @SuppressWarnings("unused") - long lcc = Long.parseLong(time); - int i = Integer.parseInt(time); - return sdr.format(new Date(i * 1000L)); - - } - - /** - * 获取距现在某一小时的时刻 - * - * @param hour hour=-1为上一个小时,hour=1为下一个小时 - * @return string - */ - public static String getLongTime(int hour) { - Calendar c = Calendar.getInstance(); // 当时的日期和时间 - int h; // 需要更改的小时 - h = c.get(Calendar.HOUR_OF_DAY) - hour; - c.set(Calendar.HOUR_OF_DAY, h); - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); - Log.v("time", df.format(c.getTime())); - return df.format(c.getTime()); - } - - /** - * 比较时间大小 - * - * @param str1:要比较的时间 - * @param str2:要比较的时间 - * @return string - */ - public static boolean isDateOneBigger(String str1, String str2) { - boolean isBigger = false; - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); - Date dt1 = null; - Date dt2 = null; - try { - dt1 = sdf.parse(str1); - dt2 = sdf.parse(str2); - } catch (ParseException e) { - e.printStackTrace(); - } - if (dt1 == null || dt2 == null) { - return false; - } else { - if (dt1.getTime() > dt2.getTime()) { - isBigger = true; - } - return isBigger; - } - } - - /** - * 当地时间 ---> UTC时间 - * - * @return string - */ - public static String Local2UTC() { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); - sdf.setTimeZone(TimeZone.getTimeZone("gmt")); - return sdf.format(new Date()); - } - - /** - * UTC时间 ---> 当地时间 - * - * @param utcTime UTC时间 - * @return s - */ - public static String utc2Local(String utcTime) { - SimpleDateFormat utcFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());//UTC时间格式 - utcFormater.setTimeZone(TimeZone.getTimeZone("UTC")); - Date gpsUTCDate = null; - try { - gpsUTCDate = utcFormater.parse(utcTime); - } catch (ParseException e) { - e.printStackTrace(); - } - SimpleDateFormat localFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());//当地时间格式 - localFormater.setTimeZone(TimeZone.getDefault()); - if (gpsUTCDate == null) { - return null; - } else { - return localFormater.format(gpsUTCDate.getTime()); - } - } -} \ No newline at end of file diff --git a/app/src/main/res/drawable/welcome.png b/app/src/main/res/drawable/welcome.png index d3dae81..a0ec2ea 100644 Binary files a/app/src/main/res/drawable/welcome.png and b/app/src/main/res/drawable/welcome.png differ