Android上的Whatsapp数据库解密

 Try_he伊 发布于 2023-01-06 21:44

我想写一个自动解密我的Whatsapp数据库的Android应用程序,所以我按照本教程将其翻译成Java.但后来我注意到Android上没有openssl二进制文件所以我问google如何手动解密aes但我找不到有用的东西.

所以基本上我得到了这个shell命令

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

$ k是64位十六进制字符串.但是当我尝试将它用作aes解密的密钥时,我得到一个带有"Unsupported key size:64 bytes"消息的InvalidKeyException.当我在我的电脑上执行此命令时,我工作得很好.

我目前正在使用这个java代码来解密数据库,它在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();
}

如果可以,请你帮助我 :)

提前谢谢,Citron

1 个回答
  • 您需要将十六进制字符串正确转换为字节数组:

    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();
    }
    

    2023-01-06 21:52 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有