import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.RequiresApi;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Base64;
import java.util.Random;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class decry {
@RequiresApi(api = Build.VERSION_CODES.O)
public static String Decrypt(String paramString){
String replac = paramString.replace("whalev2://", "").substring(10);
String rot13= rot13(replac);
String str="";
ByteArrayOutputStream byteArrayOutputStream = null;
ByteArrayInputStream byteArrayInputStream = null;
GZIPInputStream gZIPInputStream = null;
try {
byteArrayOutputStream = new ByteArrayOutputStream();
byteArrayInputStream = new ByteArrayInputStream(Base64.getDecoder().decode(rot13.getBytes("utf-8")));
gZIPInputStream = new GZIPInputStream(byteArrayInputStream);
byte[] bArr = new byte[1024];
while (true) {
int read = gZIPInputStream.read(bArr);
if (read == -1) {
break;
}
byteArrayOutputStream.write(bArr, 0, read);
}
String byteArray = byteArrayOutputStream.toString();
// str=byteArray;
// Log.e("byteArray::::",byteArray);
//
// String rot13s= rot13(byteArray.replace("whale://", ""));
// Log.e("rot13s::::",rot13s);
String replace = byteArray.replace("whale://", "");
if (!TextUtils.isEmpty(replace)) {
replace = replace.substring(2, replace.length() - 1);
Log.e("rot13s:222:::",replace);
replace = URLDecoder.decode(replace, "UTF-8");
replace = rot13(replace);
Log.e("rot13s:333:::",replace);
byte[] var9 = Base64.getDecoder().decode(replace);
str = new String(var9, "utf-8");
if (str.startsWith("codes=")) {
str = str.substring(6);
try {
str = URLDecoder.decode(str, "UTF-8");
} catch (UnsupportedEncodingException var4) {
str = str.substring(6);
}
// Log.e("replace::::",str);
}
}
gZIPInputStream.close();
byteArrayInputStream.close();
byteArrayOutputStream.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
byteArrayOutputStream.close();
byteArrayInputStream.close();
gZIPInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return str;
}
@RequiresApi(api = Build.VERSION_CODES.O)
public static String Encrypt(String paramString){
String str="";
try {
String codes = "codes=" + URLEncoder.encode(paramString, "UTF-8");
String Base64Data = Base64.getEncoder().encodeToString(codes.getBytes(StandardCharsets.UTF_8));
String rot13= rot13(Base64Data);
String MD5 = getMD5(paramString);
String whale = "whale://" + MD5.substring(4, 6) + URLEncoder.encode(rot13, "UTF-8") + MD5.substring(0, 1);
str=whale;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream);
gZIPOutputStream.write(whale.getBytes());
gZIPOutputStream.close();
String Base64ByteArray = Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray());
byteArrayOutputStream.close();
Base64ByteArray = rot13(Base64ByteArray);
str= "whalev2://" + generateRandomString(10) + Base64ByteArray;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
/**
* rot13
* @param input
* @return
*/
public static String rot13(String input) {
byte[] bytes = input.getBytes();
char[] output = new char[bytes.length];
for (int i = 0; i < bytes.length; i++) {
byte b = bytes[i];
char base;
int result;
if (b >= '0' && b <= '9') {
base = '0';
result = (b - '0' + 5) % 10;
} else {
base = 'A';
if (b >= 'A' && b <= 'Z') {
result = b - 'A';
} else {
byte lowerCase = 'a';
if (b < 'a' || b > 'z') {
output[i] = (char) b;
continue;
}
result = b - 'a';
base = (char)lowerCase;
}
result = (result + 13) % 26;
}
output[i] = (char) (result + base);
}
return String.valueOf(output);
}
private static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
public static String getMD5(String s) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
StringBuilder sb = new StringBuilder(messageDigest.length * 2);
for (int i = 0; i < messageDigest.length; i++) {
sb.append(HEX_DIGITS[(messageDigest[i] & 0xf0) >>> 4]);
sb.append(HEX_DIGITS[messageDigest[i] & 0x0f]);
}
return sb.toString().toLowerCase();
// return toHexString(messageDigest);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
public static String generateRandomString(int length) {
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
StringBuilder randomString = new StringBuilder(length);
SecureRandom random = new SecureRandom();
for (int i = 0; i < length; i++) {
int randomIndex = random.nextInt(characters.length());
char randomChar = characters.charAt(randomIndex);
randomString.append(randomChar);
}
return randomString.toString();
}
}
02-13
918
10-09
691
06-12
3271
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交