Python RSA 모듈

Python RSA 모듈을 이용한 예제 입니다.
rsa 1.3.3 : http://pypi.python.org/pypi/rsa

#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
decrypt(cypher, key)
    Decrypts a cypher with the private key 'key'
encrypt(message, key)
    Encrypts a string 'message' with the public key 'key'
gen_pubpriv_keys(nbits)
    Generates public and private keys, and returns them as (pub, priv).

    The public key consists of a dict {e: ..., , n: ....). The private key consists of a dict {d: ...., p: ...., q: ....).
sign(message, key)
    Signs a string 'message' with the private key 'key'
verify(cypher, key)
    Verifies a cypher with the public key 'key'
'''

import rsa

ekey = {'e':777, 'n':901}
print rsa.encrypt('Hello World!', ekey)

dkey = {'d':121, 'p':17, 'q':53}
msg = 'eJzTyCkw5PIxMTTy4Ur0MbcwBFFGxkZIlDGEsjA0AVFmJhZIgkYGlkgqzczACsGUHgClDBSo'
print rsa.decrypt(msg, dkey)

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다