同级目录下放置 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())
网友评论