mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-17 08:35:37 -04:00
RSAPadding: attempt
This commit is contained in:
parent
6e0f5e819c
commit
ede65a8c90
@ -986,51 +986,20 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
|||||||
public void fixRSAPadding() throws Exception {
|
public void fixRSAPadding() throws Exception {
|
||||||
// welcome to the territory of YOLO; I'll be your tour guide for today.
|
// welcome to the territory of YOLO; I'll be your tour guide for today.
|
||||||
|
|
||||||
System.out.println("Before: " + KeyFactory.getInstance("RSA") + " ; " + KeyFactory.getInstance("RSA").getProvider().toString());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/*
|
if (android.os.Build.VERSION.SDK_INT > 23) { // Nougat
|
||||||
System.out.println(Cipher.getInstance("RSA"));
|
// GetInstance.getServices("KeyPairGenerator", algorithm);
|
||||||
System.out.println(Cipher.getInstance("RSA/ECB/PKCS1Padding"));
|
// Since Android 7, it use sun.security.jca.GetInstance
|
||||||
*/
|
|
||||||
|
Class.forName("sun.security.jca.GetInstance")
|
||||||
Cipher rsaPkcs1Cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
|
.getDeclaredMethod("getServices", String.class, String.class)
|
||||||
Cipher rsaCipher = Cipher.getInstance("RSA");
|
.invoke(null, new Object[]{"Cipher", "RSA"});
|
||||||
/*
|
|
||||||
for (Provider.Service ser : rsaPkcs1Cipher.getProvider().getServices()) {
|
|
||||||
System.out.println(" - " + ser.getType() + ", " + ser.getAlgorithm());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
Provider.Service servicePkcs1 = rsaPkcs1Cipher.getProvider().getService("Cipher", "RSA/ECB/PKCS1Padding");
|
|
||||||
Provider rsaProvider = rsaCipher.getProvider();
|
|
||||||
|
|
||||||
Map pkcs1Map = new ArrayMap();
|
|
||||||
for (Map.Entry entry : servicePkcs1.getProvider().entrySet()) {
|
|
||||||
pkcs1Map.put(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT < 24) {
|
|
||||||
rsaProvider.putAll(pkcs1Map);
|
|
||||||
} else {
|
} else {
|
||||||
// Method rsaMethod_clear = rsaProvider.getClass().getDeclaredMethod("implClear");
|
ArrayList<Provider.Service> rsaList = Services.getServices("Cipher.RSA");
|
||||||
Method rsaMethod_putAll = rsaProvider.getClass().getDeclaredMethod("implPutAll", Map.class);
|
ArrayList<Provider.Service> rsaPkcs1List = Services.getServices("Cipher.RSA/ECB/PKCS1PADDING");
|
||||||
// rsaMethod_clear.setAccessible(true);
|
rsaList.clear();
|
||||||
rsaMethod_putAll.setAccessible(true);
|
rsaList.addAll(rsaPkcs1List);
|
||||||
|
|
||||||
// rsaMethod_clear.invoke(rsaProvider);
|
|
||||||
rsaMethod_putAll.invoke(rsaProvider, pkcs1Map);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 23) { // Marshmallow
|
|
||||||
// FUUUUU I DON'T KNOW FIXME
|
|
||||||
} else {
|
|
||||||
ArrayList<Provider.Service> rsaList = Services.getServices("Cipher.RSA");
|
|
||||||
ArrayList<Provider.Service> rsaPkcs1List = Services.getServices("Cipher.RSA/ECB/PKCS1PADDING");
|
|
||||||
rsaList.clear();
|
|
||||||
rsaList.addAll(rsaPkcs1List);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
} catch (Throwable th) {
|
} catch (Throwable th) {
|
||||||
th.printStackTrace();
|
th.printStackTrace();
|
||||||
|
|
||||||
@ -1058,10 +1027,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
System.out.println("After: " + KeyFactory.getInstance("RSA") + " ; " + KeyFactory.getInstance("RSA").getProvider().toString());
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Provider provider = KeyFactory.getInstance("RSA").getProvider();
|
Provider provider = KeyFactory.getInstance("RSA").getProvider();
|
||||||
System.out.println("Before: " + provider.getService("KeyService", "RSA"));
|
System.out.println("Before: " + provider.getService("KeyService", "RSA"));
|
||||||
|
35
app/src/main/java/net/kdt/pojavlaunch/Modifiable.java
Normal file
35
app/src/main/java/net/kdt/pojavlaunch/Modifiable.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package net.kdt.pojavlaunch;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.lang.reflect.*;
|
||||||
|
|
||||||
|
// This class simply get the modifiable original Collection from unmodifable one.
|
||||||
|
public class Modifiable
|
||||||
|
{
|
||||||
|
public static <E> Collection<E> modifyCollection(Collection<? extends E> collection) {
|
||||||
|
if (collection == null) {
|
||||||
|
throw new NullPointerException("collection == null");
|
||||||
|
} else if (collection.getClass().getSimpleName().startsWith("Unmodifiable")) {
|
||||||
|
Field collectionField = null;
|
||||||
|
try {
|
||||||
|
collectionField = Class.forName("java.util.Collections$UnmodifiableCollection").getDeclaredField("c");
|
||||||
|
} catch (Throwable th) {
|
||||||
|
th.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (collectionField != null) {
|
||||||
|
collectionField.setAccessible(true);
|
||||||
|
try {
|
||||||
|
return (Collection<E>) collectionField.get(collection);
|
||||||
|
} catch (Throwable th) {
|
||||||
|
th.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (Collection<E>) collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <E> Set<E> modifySet(Set<? extends E> set) {
|
||||||
|
return (Set<E>) modifyCollection(set);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user