import rsa
import os

#---------------------------------------------------------------------------------
# Generating key pairs
#---------------------------------------------------------------------------------
publicKey, privateKey = rsa.generateKeyPair("RSA-1024")

# generateKeyPair function returns 2 tuples :
	# - the public key : (e,n)
	# - the private key : (d,n)
	
# generateKeyPair takes 1 argument, a string that is a RSA-NUMBER (key size)
# RSA numbers below RSA-1024 are not secured enough,
# use them for better performances during developement
	# - "RSA-2048"
	# - "RSA-1536"
	# - "RSA-1024"
	# - "RSA-896"
	# - "RSA-768"
	# - "RSA-704"
	# - "RSA-576"


#---------------------------------------------------------------------------------
# Crypt a message
#---------------------------------------------------------------------------------
data = ["abc", 1, 7]
data_crypted = rsa.crypt(data, key)

# it takes 2 arguments :
Example #2
0
import rsa

# FAKE WORKING EXEMPLE on PYTHON 3
# from https://github.com/Theo6898/Python-RSA-module
# version 1.0 - 15 november 2015

# For security issues, server and user need to know their respective public keys for sure
# You need a trust authoritie to check if the public keys are correct

#Generating key pairs
publicKeyUser, privateKeyUser = rsa.generateKeyPair("RSA-1024")
publicKeyServer, privateKeyServer = rsa.generateKeyPair("RSA-1024")

# user crypt message with server's public key and sign it with its own private key
data = ["Hello this a message", "And another one !"]
data_crypted = rsa.crypt(data, publicKeyServer)
data_signed = rsa.sign(data, privateKeyUser)

# server decrypt the message with its own private key and check if the message has been signed by the user itself
data_decrypted = rsa.decrypt(data_crypted, privateKeyServer)
if rsa.check_signature(data_decrypted, data_signed, publicKeyUser) == True:
	print("Message received :\n", data_decrypted)
else:
	print("Invalid signature, man in the middle attack")
Example #3
0
import rsa

# FAKE WORKING EXEMPLE on PYTHON 3
# from https://github.com/Theo6898/Python-RSA-module
# version 1.0 - 15 november 2015

# For security issues, server and user need to know their respective public keys for sure
# You need a trust authoritie to check if the public keys are correct

#Generating key pairs
publicKeyUser, privateKeyUser = rsa.generateKeyPair("RSA-1024")
publicKeyServer, privateKeyServer = rsa.generateKeyPair("RSA-1024")

# user crypt message with server's public key and sign it with its own private key
data = ["Hello this a message", "And another one !"]
data_crypted = rsa.crypt(data, publicKeyServer)
data_signed = rsa.sign(data, privateKeyUser)

# server decrypt the message with its own private key and check if the message has been signed by the user itself
data_decrypted = rsa.decrypt(data_crypted, privateKeyServer)
if rsa.check_signature(data_decrypted, data_signed, publicKeyUser) == True:
    print("Message received :\n", data_decrypted)
else:
    print("Invalid signature, man in the middle attack")