· 6 years ago · Jul 07, 2019, 04:30 AM
1// Small utility to recover forgotten Tizen certificate password.
2// If you still have the Eclipse IDE remembering the password, you
3// can find it in encrypted form in a file:
4// <WORKSPACE>/.metadata/.plugins/org.tizen.common.sign/profiles.xml
5// Then simply paste the password from that file to this utility as
6// a command line parameter.
7
8// Code is mostly copied from Tizen IDE source code.
9package fi.ustun.tizendecipher;
10
11import javax.crypto.Cipher;
12import javax.crypto.SecretKey;
13import javax.crypto.SecretKeyFactory;
14import javax.crypto.spec.DESedeKeySpec;
15
16public class Main {
17 private final static char[] ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
18
19 private static int[] toInt = new int[128];
20
21 static {
22 for(int i=0; i< ALPHABET.length; i++){
23 toInt[ALPHABET[i]]= i;
24 }
25 }
26
27 public static byte[] base64Decode(String s){
28 int delta = s.endsWith( "==" ) ? 2 : s.endsWith( "=" ) ? 1 : 0;
29 byte[] buffer = new byte[s.length()*3/4 - delta];
30 int mask = 0xFF;
31 int index = 0;
32 for(int i=0; i< s.length(); i+=4){
33 int c0 = toInt[s.charAt( i )];
34 int c1 = toInt[s.charAt( i + 1)];
35 buffer[index++]= (byte)(((c0 << 2) | (c1 >> 4)) & mask);
36 if(index >= buffer.length){
37 return buffer;
38 }
39 int c2 = toInt[s.charAt( i + 2)];
40 buffer[index++]= (byte)(((c1 << 4) | (c2 >> 2)) & mask);
41 if(index >= buffer.length){
42 return buffer;
43 }
44 int c3 = toInt[s.charAt( i + 3 )];
45 buffer[index++]= (byte)(((c2 << 6) | c3) & mask);
46 }
47 return buffer;
48 }
49
50 private static final String password = "KYANINYLhijklmnopqrstuvwx";
51 private static SecretKey SECRETE_KEY;
52 private static Cipher DES_CIPHER;
53 private static final String ALGORITHM = "DESede";
54
55 static {
56 try {
57 byte key[] = password.getBytes();
58 DESedeKeySpec desKeySpec = new DESedeKeySpec(key);
59 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
60 SECRETE_KEY = keyFactory.generateSecret(desKeySpec);
61
62 DES_CIPHER = Cipher.getInstance(ALGORITHM + "/ECB/PKCS5Padding");
63 } catch (Throwable t) {
64 System.out.println("Exception occurred while creating secret key" + t);
65 }
66 }
67
68 private static byte[] decryptByDES(byte[] bytes) throws Exception{
69 DES_CIPHER.init(Cipher.DECRYPT_MODE, SECRETE_KEY);
70
71 return DES_CIPHER.doFinal(bytes);
72 }
73
74 public static String getDecryptedString(String s) throws Exception {
75 return new String(decryptByDES(base64Decode(s)));
76 }
77
78 public static void main(String[] args) {
79 if (args.length < 1)
80 System.exit(-1);
81
82 try {
83 System.out.println(getDecryptedString(args[0]));
84 } catch (Exception e) {
85
86 }
87 }
88}