PDF 解密方案

全是干货 直接复制可用!!!

如果你感觉比较使用请我吃个馒头吧!点个红心也可以!!!

已知密码解密

implementation 'com.tom-roush:pdfbox-android:2.0.6.0'

  /**
     * 解除保护
     * @param filepath 文件路径   
     * @param filepath password 密码   
     */
    public static boolean UnPdfEncrypt(String filepath, String password) {
        File file = new File(filepath);
        try {
            PDDocument document = PDDocument.load(file, password);
            document.setAllSecurityToBeRemoved(true);
            document.save(filepath);
            document.close();

            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }

未知密码简单破解

简单破解 就是已知简单密码组合 进行循环解密如果解密成功即停止解密

所有密码组合&密码字典

如果你没积分 可以直接联系我 留下邮箱!或者自行生成密码字典

 /**
     * 解除保护
     * @param filepath 文件路径
     * @param filepath password ArrayList
     */
    public static boolean UnPdfEncrypts(String filepath, ArrayList<String> ps) {
        for (String s :ps){
            boolean b = UnPdfEncrypt(filepath, s);
            if (b){
                //解密成功
                return true;
            }
        }
        //所添加密码里面不包含文件所需密码
        return false;
    }

未知密码暴力破解

密码可能会包含的字符集合

char[] fullCharSource = { '1','2','3','4','5','6','7','8','9','0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',  'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',  'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '{', '}', '|', ':', '"', '<', '>', '?', ';', '\'', ',', '.', '/', '-', '=', '`'};

 /**
     * @param url     要解密的pdf路径
     * @param context 页面对象
     * @param listen  回掉
     * @param minline 密码最短几位
     * @param maxline 密码最长几位
     */
    public void decrypt(String url, Activity context, EncryptProgress listen, int minline, int maxline) {
        new Thread(() -> {
            long time = System.currentTimeMillis();
            File file = new File(url);
            int maxLength = maxline;
            int counter = 0;
            int enter = 1;
            int position = 0;
            StringBuilder buider = new StringBuilder();
            int index = pdfEncrypt(file, "");
            if (index == 1) {
                listen.onSuccess(buider.toString(), position);
                return;
            }
            for (int i = 0; i < minline; i++) {
                if (i == 0) {
                    counter = 1;
                } else {
                    counter = counter * fullCharLength + 1;
                }
            }
            for (int i = 0; i < maxline + 1; i++) {
                if (i == 0) {
                    enter = 1;
                } else {
                    enter = enter * fullCharLength + 1;
                }
            }


            while (buider.toString().length() <= maxLength) {
                buider = new StringBuilder(maxLength * 2);
                int _counter = counter;
                //10进制转换成26进制
                while (_counter >= fullCharLength) {
                    //获得低位
                    buider.insert(0, fullCharSource[_counter % fullCharLength]);
                    _counter = _counter / fullCharLength;
                    _counter--;
                }

                //最高位
                buider.insert(0, fullCharSource[_counter]);
                counter++;
                position++;
                if (pdfEncrypt(file, buider.toString()) == 0) {
                    int i1 = position % 200;
                    int finalI1 = position;
                    StringBuilder finalBuider = buider;
                    context.runOnUiThread(() -> listen.onSpeed(i1, finalI1, finalBuider.toString()));
                } else {
                    listen.onSuccess(buider.toString(), position);
                    return;
                }
                if (position == 10000) {
                    Log.d("-----TAG---", time + "\n" + System.currentTimeMillis());
                }
                if (enter == counter && enter != 1) {//区域中间得
                    int finalPosition = position;
                    context.runOnUiThread(() -> listen.onError(finalPosition));
                    return;
                }
            }

        }).start();
    }

未知密码组合破解

这个解密方式 就是暴力破解的简化版
需要用户输入一些字符然后自行分割,重新全部排序进行测试哪个密码是正确的!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值