def GetPublicKey(pem_file):
    'Extract public exponent and modulus from PEM file.'
    result = subprocess.run(['openssl', 'rsa', '-in', pem_file, '-text', '-noout'], stdout=subprocess.PIPE, encoding='utf-8')
    modulus_raw = []
    in_modulus = False
    for line in result.stdout.splitlines():
        if line.startswith('modulus'):
            in_modulus = True
        elif (not line.startswith(' ')):
            in_modulus = False
        elif in_modulus:
            modulus_raw.extend(line.strip().strip(':').split(':'))
        if line.startswith('publicExponent'):
            exp = int(line.split(' ')[1], 10)
    modulus_raw.reverse()
    modulus = bytearray((int(x, 16) for x in modulus_raw[:256]))
    return (struct.pack('<Q', exp), modulus)
Extract public exponent and modulus from PEM file.
def GetPublicKey(pem_file):
    
    result = subprocess.run(['openssl', 'rsa', '-in', pem_file, '-text', '-noout'], stdout=subprocess.PIPE, encoding='utf-8')
    modulus_raw = []
    in_modulus = False
    for line in result.stdout.splitlines():
        if line.startswith('modulus'):
            in_modulus = True
        elif (not line.startswith(' ')):
            in_modulus = False
        elif in_modulus:
            modulus_raw.extend(line.strip().strip(':').split(':'))
        if line.startswith('publicExponent'):
            exp = int(line.split(' ')[1], 10)
    modulus_raw.reverse()
    modulus = bytearray((int(x, 16) for x in modulus_raw[:256]))
    return (struct.pack('<Q', exp), modulus)