· 5 years ago · Jul 14, 2020, 04:32 PM
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6package OreoRE;
7import java.util.Base64;
8import java.security.NoSuchAlgorithmException;
9import java.security.spec.InvalidKeySpecException;
10import javax.crypto.Cipher;
11import javax.crypto.CipherInputStream;
12import javax.crypto.CipherOutputStream;
13import javax.crypto.SecretKey;
14import javax.crypto.SecretKeyFactory;
15import javax.crypto.spec.PBEKeySpec;
16
17/**
18 *
19 * @author kaporos
20 */
21public class Main {
22 private final String CYPHER_TRANSFORMATION = "AES";
23 private final byte[] MASTER_SALT = STATIC_INIT_STRING.getBytes();
24 private byte[] PASSWORD_SALT = STATIC_INIT_STRING.getBytes();
25 private String PASSWORD_SALT_STRING = STATIC_INIT_STRING;
26 private static String STATIC_INIT_STRING;
27 private static SecretKey sMasterKey;
28 /**
29 * @param args the command line arguments
30 */
31 public String decryptString(String str) throws Exception {
32 sMasterKey = getMasterKey("pass word 11", "fCTE0uDA2lc9xpJvcNkhdjd/b0VlaSY/IwLP1tojugpuSDxgtcyG+44aAPQXrA82");
33 return decrypt(sMasterKey, "pass word 11");
34 }
35
36 private String decrypt(SecretKey secretKey, String str) throws Exception {
37 if (secretKey == null) {
38 throw new Exception("SecretKey missing, cannot decrypt.");
39 } else if (str == null) {
40 return null;
41 } else {
42 Cipher instance = Cipher.getInstance(CYPHER_TRANSFORMATION);
43 instance.init(2, secretKey);
44 return new String(instance.doFinal(Base64.getDecoder().decode(str)));
45 }
46 }
47 private SecretKey getPasswordKey(String str) throws Exception {
48 byte[] decoded = Base64.getDecoder().decode(PASSWORD_SALT_STRING);
49 char[] strChar = str.toCharArray();
50 return generateKey(strChar,decoded);
51 }
52 private SecretKey getMasterKey(String str, String str2) throws Exception {
53 return generateKey(decrypt(getPasswordKey(str), str2).toCharArray(), MASTER_SALT);
54 }
55
56 private static SecretKey generateKey(char[] cArr, byte[] bArr) throws NoSuchAlgorithmException, InvalidKeySpecException {
57 return SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").generateSecret(new PBEKeySpec(cArr, bArr, 1000, 256));
58 }
59 public static void main(String[] args) {
60 StringBuilder sb = new StringBuilder(40);
61 for (int i = 0; i < 20; i++) {
62 sb.append(Integer.toHexString(i));
63 }
64 STATIC_INIT_STRING = sb.toString();
65
66 // TODO code application logic here
67 }
68
69}