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();
}
未知密码组合破解
这个解密方式 就是暴力破解的简化版
需要用户输入一些字符然后自行分割,重新全部排序进行测试哪个密码是正确的!