Skip to content

Instantly share code, notes, and snippets.

@rgngl
Created December 9, 2013 07:09
Show Gist options
  • Save rgngl/7868448 to your computer and use it in GitHub Desktop.
Save rgngl/7868448 to your computer and use it in GitHub Desktop.
Recovery utility for Tizen certificate passwords
// Small utility to recover forgotten Tizen certificate password.
// If you still have the Eclipse IDE remembering the password, you
// can find it in encrypted form in a file:
// <WORKSPACE>/.metadata/.plugins/org.tizen.common.sign/profiles.xml
// Then simply paste the password from that file to this utility as
// a command line parameter.
// Code is mostly copied from Tizen IDE source code.
package fi.ustun.tizendecipher;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
public class Main {
private final static char[] ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
private static int[] toInt = new int[128];
static {
for(int i=0; i< ALPHABET.length; i++){
toInt[ALPHABET[i]]= i;
}
}
public static byte[] base64Decode(String s){
int delta = s.endsWith( "==" ) ? 2 : s.endsWith( "=" ) ? 1 : 0;
byte[] buffer = new byte[s.length()*3/4 - delta];
int mask = 0xFF;
int index = 0;
for(int i=0; i< s.length(); i+=4){
int c0 = toInt[s.charAt( i )];
int c1 = toInt[s.charAt( i + 1)];
buffer[index++]= (byte)(((c0 << 2) | (c1 >> 4)) & mask);
if(index >= buffer.length){
return buffer;
}
int c2 = toInt[s.charAt( i + 2)];
buffer[index++]= (byte)(((c1 << 4) | (c2 >> 2)) & mask);
if(index >= buffer.length){
return buffer;
}
int c3 = toInt[s.charAt( i + 3 )];
buffer[index++]= (byte)(((c2 << 6) | c3) & mask);
}
return buffer;
}
private static final String password = "KYANINYLhijklmnopqrstuvwx";
private static SecretKey SECRETE_KEY;
private static Cipher DES_CIPHER;
private static final String ALGORITHM = "DESede";
static {
try {
byte key[] = password.getBytes();
DESedeKeySpec desKeySpec = new DESedeKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
SECRETE_KEY = keyFactory.generateSecret(desKeySpec);
DES_CIPHER = Cipher.getInstance(ALGORITHM + "/ECB/PKCS5Padding");
} catch (Throwable t) {
System.out.println("Exception occurred while creating secret key" + t);
}
}
private static byte[] decryptByDES(byte[] bytes) throws Exception{
DES_CIPHER.init(Cipher.DECRYPT_MODE, SECRETE_KEY);
return DES_CIPHER.doFinal(bytes);
}
public static String getDecryptedString(String s) throws Exception {
return new String(decryptByDES(base64Decode(s)));
}
public static void main(String[] args) {
if (args.length < 1)
System.exit(-1);
try {
System.out.println(getDecryptedString(args[0]));
} catch (Exception e) {
}
}
}
@RizalSaputra
Copy link

Hello, I'm trying using your code to decrypt certificate password but always error at "package fi.ustun.tizendecipher;"
Where could I find tizen pacakge for java?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment