2014-06-30 3 views
1

내 Whatsapp 데이터베이스를 자동으로 해독하는 Android 애플리케이션을 작성하고자하므로 this 자습서를 따라 Java로 번역했습니다. 하지만 안드로이드에는 openssl 바이너리가 없다는 것을 알아 차 렸습니다. 그래서 수동으로 암호 해독 방법을 구글에 요청했지만 유용한 것을 찾을 수 없었습니다.Android에서 Whatsapp 데이터베이스 암호 해독

그래서 기본적으로 난 64 진수로 문자열 인 $ K와 함께이 쉘 명령을

openssl enc -aes-256-cbc -d -nosalt -nopad -bufsize 16384 -in msgstore.db.crypt7.nohdr -K $k -iv $iv > msgstore.db 

을 얻었다. 하지만 암호 해독을위한 키로 사용하려고하면 "지원되지 않는 키 크기 : 64 바이트"라는 메시지가있는 InvalidKeyException이 발생합니다. 컴퓨터에서이 명령을 실행하면 완벽하게 작동합니다.

저는 현재 데이터베이스를 해독하기 위해 자바 코드를 사용하고 있으며 cipher.init에 실패

public void decryptDatabase(String k, String iv) 

throws InvalidKeyException, InvalidAlgorithmParameterException, 
     NoSuchAlgorithmException, NoSuchPaddingException, IOException { 

    File extStore = Environment.getExternalStorageDirectory(); 
    FileInputStream fis = new FileInputStream(extStore 
      + "/WhatsApp/Databases/msgstore.db.crypt7.nohdr"); 
    FileOutputStream fos = new FileOutputStream(extStore + "/Decrypted.db"); 

    SecretKeySpec sks = new SecretKeySpec(k.getBytes(), "AES"); 
    Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); 
    cipher.init(Cipher.DECRYPT_MODE, sks, 
      new IvParameterSpec(iv.getBytes())); 
    CipherInputStream cis = new CipherInputStream(fis, cipher); 
    int b; 
    byte[] d = new byte[8]; 
    while ((b = cis.read(d)) != -1) { 
     fos.write(d, 0, b); 
    } 
    fos.flush(); 
    fos.close(); 
    cis.close(); 
} 

사전에

감사합니다 :) 수 있다면,

+0

스택 추적 및 예외는 무엇입니까? 오류 메시지? –

+0

예외 메시지는 "InvalidKeyException : 지원되지 않는 키 크기 : 64 바이트" – Citron

+0

명확히하기 : 게시 한 자바 코드는 PC에서는 실행되지만 Android 디바이스에서는 실행되지 않습니다. –

답변

5
유자를 도와주세요

16 진수 문자열을 올바르게 바이트 배열로 변환해야합니다.

private static byte[] hexStringToByteArray(String s) { 
    int len = s.length(); 
    byte[] data = new byte[len/2]; 
    for (int i = 0; i < len; i += 2) { 
     data[i/2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) 
          + Character.digit(s.charAt(i+1), 16)); 
    } 
    return data; 
} 

public void decryptDatabase(String k, String iv) throws InvalidKeyException, InvalidAlgorithmParameterException, 
     NoSuchAlgorithmException, NoSuchPaddingException, IOException { 

    File extStore = Environment.getExternalStorageDirectory(); 
    FileInputStream fis = new FileInputStream(extStore 
      + "/WhatsApp/Databases/msgstore.db.crypt7.nohdr"); 
    FileOutputStream fos = new FileOutputStream(extStore + "/Decrypted.db"); 

    SecretKeySpec sks = new SecretKeySpec(hexStringToByteArray(k), "AES"); 
    Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); 
    cipher.init(Cipher.DECRYPT_MODE, sks, 
      new IvParameterSpec(hexStringToByteArray(iv))); 
    CipherInputStream cis = new CipherInputStream(fis, cipher); 
    int b; 
    byte[] d = new byte[8]; 
    while ((b = cis.read(d)) != -1) { 
     fos.write(d, 0, b); 
    } 
    fos.flush(); 
    fos.close(); 
    cis.close(); 
} 
+0

대단히 감사합니다. :) unfortunatelly 귀하의 답변에 투표하기에 충분한 평판이 없습니다./ – Citron

+0

안녕하세요, 우리 모두 가져올 수 있습니까? 해당 데이터베이스에서 상태를 문의 하시겠습니까? 연락처 상태 의미 : 사람들이 상태를 다음과 같이 설정했습니다. i busy, available. 등, 캔트 토크 Whatsapp 전용 –

+0

decryptDatabase (k, iv); 위의 'k'와 'iv'가 무엇인지 설명합니다. 설명해주십시오. – Ravi