这里记录一下破解aspose-words-18.8-jdk16.jar包的过程,该组件收费,这里仅用于学习。
1)使用JByteMod工具找开aspose-words-18.8-jdk16.jar,找到证书加载的代码,如下的License;
2)找到验证证书的代码,如下zzZLR.zzz(Node, Node)方法
3)清除方法体,保留方法签名
4)另保存aspose-words-18.8-jdk16-crack.jar,打开这个JAR,查看确实已经清除了;
5) 因为改了.class文件,会被检测到,需要删除aspose-words-18.8-jdk16-crack.jar中的指纹文件
接下来,就可以正常工作了!
附代码:
public class Xls2Pdf {
/**
* 获取license
*
* @return
*/
public static boolean getLicense() {
boolean result = false;
try {
InputStream is = Xls2Pdf.class.getClassLoader().getResourceAsStream("/license.xml");
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* 支持DOC, DOCX, OOXML, RTF, HTML, OpenDocument, PDF, EPUB, XPS, SWF等相互转换<br>
*
* @param args
*/
public static void main(String[] args) {
// 验证License
if (!getLicense()) {
return;
}
try {
long old = System.currentTimeMillis();
Workbook wb = new Workbook("test.xlsx");// 原始excel路径
File pdfFile = new File("test-xlsx.pdf");// 输出路径
FileOutputStream fileOS = new FileOutputStream(pdfFile);
wb.save(fileOS, SaveFormat.PDF);
long now = System.currentTimeMillis();
System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");
} catch (Exception e) {
e.printStackTrace();
}
}
}
证书文件:SerialNumber与Signature随便写,反正不会验证
<License>
<Data>
<Products>
<Product>Aspose.Total for Java</Product>
</Products>
<EditionType>Enterprise</EditionType>
<SubscriptionExpiry>20991231</SubscriptionExpiry>
<LicenseExpiry>20991231</LicenseExpiry>
<SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>
</Data>
<Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>
</License>