unidbg或者java层解密方法IDEA中打包成jar包供python调用方法

文章介绍了如何通过Python的jpype库来启动JVM并调用jar包中的Java类进行RSA加密方法,特别是在处理乱码问题时的参数设置。示例中展示了调用com.bytedance.frameworks.core.encrypt.CS类的RSA_encrypt方法,并打印加密结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、导出jar包方法

(1)配置jar包参数

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

(2)创建生成jar包

在这里插入图片描述
在这里插入图片描述

成功生成!

在这里插入图片描述

二、Python代码调用

import jpype

jvmPath = jpype.getDefaultJVMPath()
d = 'unidbg-android.jar'  # 对应jar地址
# jpype.startJVM(jvmPath, "-ea", "-Djava.class.path=" + d + "")
jpype.startJVM(jvmPath, "-Dfile.encoding=utf-8", "-Djava.class.path=" + d + "")  # 输出乱码时使用
java = jpype.JClass("com.bytedance.frameworks.core.encrypt.CS")()     # 从com开始找到打包jar的类
signature = java.RSA_encrypt("hello world")         # 调用java的com.bytedance.frameworks.core.encrypt.CS类的RSA_encrypt方法
print(signature)
jpype.shutdownJVM()     # 关闭JVM(注意,必须在所有子线程结束后再关闭,不用子线程调用加密方法会失败)
Python调用JAR实现解密算法,可以通过以下几种方法实现: 1. **使用`subprocess`模块**: 通过Python的`subprocess`模块,可以调用外部的Java程序来执行解密算法。具体步骤如下: - 编写一个Java程序,解密算法的实现。 - 编译Java程序生JAR。 - 在Python中使用`subprocess`模块调用JAR,并传递必要的参数。 示例代码: ```python import subprocess def decrypt(encrypted_text): # 调用Java程序并传递加密文本作为参数 result = subprocess.run(['java', '-jar', 'decryptor.jar', encrypted_text], capture_output=True, text=True) return result.stdout.strip() encrypted_text = "your_encrypted_text" decrypted_text = decrypt(encrypted_text) print(f"Decrypted text: {decrypted_text}") ``` 2. **使用`jpype`库**: `jpype`是一个Python库,可以在Python中直接调用Java类和方法。首先需要安装`jpype`库: ```sh pip install jpype1 ``` 示例代码: ```python import jpype import jpype.imports from jpype.types import * # 启动JVM jpype.startJVM(classpath=['decryptor.jar']) # 导入Java类 from com.example.decryptor import Decryptor def decrypt(encrypted_text): decryptor = Decryptor() return decryptor.decrypt(encrypted_text) encrypted_text = "your_encrypted_text" decrypted_text = decrypt(encrypted_text) print(f"Decrypted text: {decrypted_text}") # 关闭JVM jpype.shutdownJVM() ``` 3. **使用`py4j`库**: `py4j`是一个Python库,可以在Python调用Java代码。首先需要安装`py4j`库: ```sh pip install py4j ``` 示例代码: ```python from py4j.java_gateway import JavaGateway # 启动网关 gateway = JavaGateway() # 获取Java类 Decryptor = gateway.jvm.com.example.decryptor.Decryptor def decrypt(encrypted_text): decryptor = Decryptor() return decryptor.decrypt(encrypted_text) encrypted_text = "your_encrypted_text" decrypted_text = decrypt(encrypted_text) print(f"Decrypted text: {decrypted_text}") ``` 以上三种方法都可以在Python调用JAR实现解密算法,具体选择哪种方法可以根据实际需求和环境来决定。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云霄IT

感谢感谢!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值