import subprocess
import os


def run_openssl(data):
    """用openssl加密data"""
    env=os.environ.copy()
    env['password']=b'\xe24U\n\xd0Q13s\x11'
    proc=subprocess.Popen(['openssl','enc','-des3','-pass','env:password'],env=env,stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE)
    proc.stdin.write(data)
    proc.stdin.flush()
    return proc

def run_md5(input_stdin):
    """计算input_stdin的md5值"""
    proc=subprocess.Popen(['md5sum'],stdin=input_stdin,stdout=subprocess.PIPE)
    return proc


input_procs=[]
hash_procs=[]
for _ in range(3):
    data=os.urandom(10)
    proc=run_openssl(data)
    input_procs.append(proc) #添加run_openssl进程到input_procs
    hash_proc=run_md5(proc.stdout)
    hash_procs.append(hash_proc) #添加run_md5进程到hash_procs
    
for proc in input_procs:
    proc.communicate() #多进程运行run_openssl结果
for proc in hash_procs:
    out,err=proc.communicate()#多进程计算md值
    print(out.strip())