Decrypt CookieCloud data using standard Java crypto
(String uuid, String encrypted, String password)
| 23 | * Decrypt CookieCloud data using standard Java crypto |
| 24 | */ |
| 25 | public static String decrypt(String uuid, String encrypted, String password) throws Exception { |
| 26 | // 1. Generate key: MD5(uuid + "-" + password) first 16 chars |
| 27 | String keyInput = uuid + "-" + password; |
| 28 | MessageDigest md = MessageDigest.getInstance("MD5"); |
| 29 | byte[] hashBytes = md.digest(keyInput.getBytes(StandardCharsets.UTF_8)); |
| 30 | |
| 31 | // Convert to hex string |
| 32 | StringBuilder hexString = new StringBuilder(); |
| 33 | for (byte b : hashBytes) { |
| 34 | String hex = Integer.toHexString(0xff & b); |
| 35 | if (hex.length() == 1) hexString.append('0'); |
| 36 | hexString.append(hex); |
| 37 | } |
| 38 | String key = hexString.toString().substring(0, 16); |
| 39 | |
| 40 | // 2. Fixed IV: 16 bytes of zeros |
| 41 | byte[] iv = new byte[16]; |
| 42 | |
| 43 | // 3. Decode base64 encrypted data |
| 44 | byte[] encryptedData = Base64.getDecoder().decode(encrypted); |
| 45 | |
| 46 | // 4. Create AES-128-CBC cipher |
| 47 | SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES"); |
| 48 | IvParameterSpec ivSpec = new IvParameterSpec(iv); |
| 49 | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); |
| 50 | cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec); |
| 51 | |
| 52 | // 5. Decrypt |
| 53 | byte[] decrypted = cipher.doFinal(encryptedData); |
| 54 | |
| 55 | return new String(decrypted, StandardCharsets.UTF_8); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Simple JSON value extractor (without external libraries) |
no outgoing calls