Beispiel #1
0
def rsa_encrypt(text, n, e):
    impl = RSAImplementation()
    n = int(n, 16) if isinstance(n, str) else n
    e = int(e, 16) if isinstance(e, str) else e
    public_key = impl.construct((n, e))

    random_number = 2  # 随便填
    result = public_key.encrypt(encrypt_string(public_key, text), random_number)[0]

    return dec2hex(result)
Beispiel #2
0
def rsa_pub_key_to_pem(n, e):
    rsa = RSAImplementation()
    rsa_key = rsa.construct((n, e))
    pem = rsa_key.exportKey()
    return pem
Beispiel #3
0
cfg.endpoint_process = Endpoint.url('http://site2.enigmabridge.com:11180')
cfg.endpoint_enroll = Endpoint.url('http://site2.enigmabridge.com:11182')
cfg.api_key = 'API_TEST'
cfg.retry = SimpleRetry(max_retry=1, jitter_base=1000, jitter_rand=250)


def create_rsa(cfg):
    cou = CreateUO(configuration=cfg,
                   tpl={TemplateFields.environment: Environment.DEV})

    rsa_key = cou.create_rsa(2048)
    return rsa_key


rsa = RSAImplementation()
base_path = '/tmp'

for idx in range(84, 100):
    print "Generating key %02d" % idx
    key = create_rsa(cfg)
    rsa_key = rsa.construct((key.n, key.e))
    pem = rsa_key.exportKey()

    file_name = os.path.join(base_path, 'pubkey_%02d.pem' % idx)
    with open(file_name, 'w') as hnd:
        hnd.write(pem)
    pass

if __name__ == "__main__":
    print "ok"
Beispiel #4
0

def load_pem_private_key(data, password=None, backend=None):
    return serialization.load_pem_private_key(data, None, get_backend(backend))


def load_pem_private_key_pycrypto(data, password=None):
    return RSA.importKey(data, passphrase=password)


rsa = RSAImplementation()
base_path = '/Users/dusanklinec/Downloads/EC2_keys'

for i in range(0, 200):
    file_name = os.path.join(base_path, 'test%d.pem' % i)
    if not os.path.exists(file_name):
        continue

    with open(file_name, 'r') as hnd:
        key = hnd.read()
        t = load_pem_private_key_pycrypto(key)

        rsa_key = rsa.construct((t.n, t.e))
        pem = rsa_key.exportKey()

        file_name = os.path.join(base_path, 'pubkey_test_%02d.pem' % i)
        with open(file_name, 'w') as hnd:
            hnd.write(pem)
    pass
pass