Created
February 2, 2020 15:56
-
-
Save IanWONeill/921a5d9602f9a08de8b2f9437c6a60f1 to your computer and use it in GitHub Desktop.
AES
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.sun.istack.internal.NotNull; | |
import com.sun.istack.internal.Nullable; | |
import javax.crypto.BadPaddingException; | |
import javax.crypto.Cipher; | |
import javax.crypto.IllegalBlockSizeException; | |
import javax.crypto.NoSuchPaddingException; | |
import javax.crypto.spec.SecretKeySpec; | |
import java.nio.charset.Charset; | |
import java.security.InvalidKeyException; | |
import java.security.Key; | |
import java.security.NoSuchAlgorithmException; | |
import java.util.Arrays; | |
public class Main | |
{ | |
private static final byte[] key = new byte[]{(byte) 121, (byte) 117, (byte) 103, (byte) 111, (byte) 102, (byte) 117, (byte) 99, (byte) 107, (byte) 121, (byte) 111, (byte) 117, (byte) 114, (byte) 115, (byte) 101, (byte) 108, (byte) 102}; | |
public static void main(String[] args) { | |
System.out.println(m("6E5EFF9182DD8CCCC03FE25812756E65874000F4DB19A47D5AB3C7DBCF3F47DD")); | |
} | |
private static final byte[] a(byte[] bArr) { | |
Key secretKeySpec = new SecretKeySpec(key, "AES"); | |
Object doFinal = new Object(); | |
try | |
{ | |
Cipher instance = Cipher.getInstance("AES"); | |
instance.init(2, secretKeySpec); | |
doFinal = instance.doFinal(bArr); | |
} | |
catch (BadPaddingException | IllegalBlockSizeException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e) | |
{ | |
e.printStackTrace(); | |
} | |
l(doFinal, "cipher.doFinal(encrypted)"); | |
return (byte[]) doFinal; | |
} | |
private static void i(String str) { | |
StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[3]; | |
String className = stackTraceElement.getClassName(); | |
String methodName = stackTraceElement.getMethodName(); | |
StringBuilder stringBuilder = new StringBuilder(); | |
stringBuilder.append("Parameter specified as non-null is null: method "); | |
stringBuilder.append(className); | |
stringBuilder.append("."); | |
stringBuilder.append(methodName); | |
stringBuilder.append(", parameter "); | |
stringBuilder.append(str); | |
Throwable illegalArgumentException = new IllegalArgumentException(stringBuilder.toString()); | |
j(illegalArgumentException); | |
throw ((IllegalArgumentException) illegalArgumentException); | |
} | |
private static <T extends Throwable> T j(T t) { | |
k((Throwable) t, Main.class.getName()); | |
return t; | |
} | |
static <T extends Throwable> T k(T t, String str) { | |
StackTraceElement[] stackTrace = t.getStackTrace(); | |
int length = stackTrace.length; | |
int i = -1; | |
for (int i2 = 0; i2 < length; i2++) { | |
if (str.equals(stackTrace[i2].getClassName())) { | |
i = i2; | |
} | |
} | |
t.setStackTrace((StackTraceElement[]) Arrays.copyOfRange(stackTrace, i + 1, length)); | |
return t; | |
} | |
public static void l(Object obj, String str) { | |
if (obj == null) { | |
StringBuilder stringBuilder = new StringBuilder(); | |
stringBuilder.append(str); | |
stringBuilder.append(" must not be null"); | |
Throwable illegalStateException = new IllegalStateException(stringBuilder.toString()); | |
j(illegalStateException); | |
throw ((IllegalStateException) illegalStateException); | |
} | |
} | |
@NotNull | |
public static final String m(@NotNull String str) { | |
o(str, "encrypted"); | |
return new String(a(b(str)), c.a); | |
} | |
public static boolean n(Object obj, Object obj2) { | |
return obj == null ? obj2 == null : obj.equals(obj2); | |
} | |
public static void o(Object obj, String str) { | |
if (obj == null) { | |
i(str); | |
throw null; | |
} | |
} | |
public static void p(String str) { | |
Throwable pVar = new p(str); | |
j(pVar); | |
throw ((p) pVar); | |
} | |
public static void q(String str) { | |
StringBuilder stringBuilder = new StringBuilder(); | |
stringBuilder.append("lateinit property "); | |
stringBuilder.append(str); | |
stringBuilder.append(" has not been initialized"); | |
p(stringBuilder.toString()); | |
throw null; | |
} | |
@NotNull | |
public static final byte[] b(@NotNull String str) { | |
o(str, "hexString"); | |
int length = str.length() / 2; | |
byte[] bArr = new byte[length]; | |
for (int i = 0; i < length; i++) { | |
int i2 = i * 2; | |
String substring = str.substring(i2, i2 + 2); | |
l(substring, "(this as java.lang.Strin\u2026ing(startIndex, endIndex)"); | |
bArr[i] = (byte) Integer.valueOf(substring, 16).intValue(); | |
} | |
return bArr; | |
} | |
} | |
final class c { | |
@NotNull | |
public static final Charset a; | |
static { | |
c cVar = new c(); | |
Charset forName = Charset.forName("UTF-8"); | |
Main.l(forName, "Charset.forName(\"UTF-8\")"); | |
a = forName; | |
Main.l(Charset.forName("UTF-16"), "Charset.forName(\"UTF-16\")"); | |
Main.l(Charset.forName("UTF-16BE"), "Charset.forName(\"UTF-16BE\")"); | |
Main.l(Charset.forName("UTF-16LE"), "Charset.forName(\"UTF-16LE\")"); | |
Main.l(Charset.forName("US-ASCII"), "Charset.forName(\"US-ASCII\")"); | |
Main.l(Charset.forName("ISO-8859-1"), "Charset.forName(\"ISO-8859-1\")"); | |
} | |
private c() { | |
} | |
} | |
final class p extends RuntimeException { | |
public p(@Nullable String str) { | |
super(str); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment