pull/594/head
jhengazuki 4 months ago
parent 6dfa0d533c
commit 41c4857674
  1. 3
      catvod/src/main/java/com/github/catvod/utils/Prefers.java
  2. 2
      quickjs/src/main/java/com/fongmi/quickjs/utils/Connect.java
  3. 9
      quickjs/src/main/java/com/fongmi/quickjs/utils/Crypto.java

@ -73,8 +73,7 @@ public class Prefers {
getPrefers().edit().putInt(key, (Integer) obj).apply();
} else if (obj instanceof Long) {
getPrefers().edit().putLong(key, (Long) obj).apply();
} else if (obj instanceof LazilyParsedNumber) {
LazilyParsedNumber number = (LazilyParsedNumber) obj;
} else if (obj instanceof LazilyParsedNumber number) {
if (number.toString().contains(".")) put(key, number.floatValue());
else put(key, number.intValue());
}

@ -85,7 +85,7 @@ public class Connect {
}
private static RequestBody getFormDataBody(Req req) {
String boundary = "--dio-boundary-" + new SecureRandom().nextInt(42949) + "" + new SecureRandom().nextInt(67296);
String boundary = "--dio-boundary-" + new SecureRandom().nextInt(42949) + new SecureRandom().nextInt(67296);
MultipartBody.Builder builder = new MultipartBody.Builder(boundary).setType(MultipartBody.FORM);
Map<String, String> params = Json.toMap(req.getData());
for (String key : params.keySet()) builder.addFormDataPart(key, params.get(key));

@ -4,6 +4,7 @@ import android.util.Base64;
import com.github.catvod.utils.Util;
import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.security.KeyFactory;
import java.security.PublicKey;
@ -38,8 +39,8 @@ public class Crypto {
SecretKeySpec keySpec = new SecretKeySpec(keyBuf, "AES");
if (iv == null) cipher.init(encrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, keySpec);
else cipher.init(encrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, keySpec, new IvParameterSpec(ivBuf));
byte[] inBuf = inBase64 ? Base64.decode(input.replaceAll("_", "/").replaceAll("-", "+"), Base64.DEFAULT) : input.getBytes("UTF-8");
return outBase64 ? Base64.encodeToString(cipher.doFinal(inBuf), Base64.NO_WRAP) : new String(cipher.doFinal(inBuf), "UTF-8");
byte[] inBuf = inBase64 ? Base64.decode(input.replaceAll("_", "/").replaceAll("-", "+"), Base64.DEFAULT) : input.getBytes(StandardCharsets.UTF_8);
return outBase64 ? Base64.encodeToString(cipher.doFinal(inBuf), Base64.NO_WRAP) : new String(cipher.doFinal(inBuf), StandardCharsets.UTF_8);
} catch (Exception e) {
e.printStackTrace();
return "";
@ -51,7 +52,7 @@ public class Crypto {
Key rsaKey = generateKey(pub, key);
int len = getModulusLength(rsaKey);
byte[] outBytes = new byte[0];
byte[] inBytes = inBase64 ? Base64.decode(input.replaceAll("_", "/").replaceAll("-", "+"), Base64.DEFAULT) : input.getBytes("UTF-8");
byte[] inBytes = inBase64 ? Base64.decode(input.replaceAll("_", "/").replaceAll("-", "+"), Base64.DEFAULT) : input.getBytes(StandardCharsets.UTF_8);
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(encrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, rsaKey);
int blockLen = encrypt ? len / 8 - 11 : len / 8;
@ -64,7 +65,7 @@ public class Crypto {
bufIdx = bufEndIdx;
outBytes = concatArrays(outBytes, tmpBytes);
}
return outBase64 ? Base64.encodeToString(outBytes, Base64.NO_WRAP) : new String(outBytes, "UTF-8");
return outBase64 ? Base64.encodeToString(outBytes, Base64.NO_WRAP) : new String(outBytes, StandardCharsets.UTF_8);
} catch (Exception e) {
e.printStackTrace();
return "";

Loading…
Cancel
Save