美文网首页
Python 调用 java 的 jar 包文件

Python 调用 java 的 jar 包文件

作者: Canon_2020 | 来源:发表于2020-04-20 09:39 被阅读0次

同级目录下放置 jar 包文件

#!/usr/local/python3
# -*- coding: utf-8 -*-
# @Date    : 2018-04-15 09:00:00
# @Author  : Canon
# @Link    : https://www.python.org
# @Version : 3.6.1

import subprocess
import chardet
import sys

class AES(object):
    def __init__(self, way, data, key):
        self.way = way
        self.data = data
        self.key = key

    def rsa(self):        
        command = "java -jar E:/PythonCase/PyScript/EncryptRSA/rsa_java/encrypt.jar"
        arg0 = self.way
        arg1 = self.data
        arg2 = self.key
        cmd = [command, arg0, arg1, arg2]
        new_cmd = " ".join(cmd)
        stdout, stderr = subprocess.Popen(
            new_cmd, stdout=subprocess.PIPE,
            stderr=subprocess.PIPE
            ).communicate()
        encoding = chardet.detect(stdout)["encoding"]
        result = stdout.decode(encoding)
        return result


if __name__ == '__main__':
    way = "encrypt"
    data = '{"deviceId":"aaaaaaa","password":"123456","userName":"bbbbb"}'
    key = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKIlnTzxmshHexeFdBqyobciNM0N1I5qZn8Oso5lfZXJO4D/gRrx8ywGVePZqyz6C5GnObCQLO4NGjZa3QhZgUcCAwEAAQ=="
    aes_obj = AES(way, data, key)
    print(aes_obj.rsa())

相关文章

网友评论

      本文标题:Python 调用 java 的 jar 包文件

      本文链接:https://www.haomeiwen.com/subject/tbqtwctx.html