python implementation of the rsa algorythem
Project description
Rsa4Py
rsa4py is a python library used to encript and decript string to lists of positive intagers
Table of Contents
[TOCM]
[TOC]
Key Generation
keys are divided into Public and Private keys. Public keys can be used to encript messages whereas Private can encript and decript.
Private Key
to generate a private Key can must use 2 larg prime numbers. the library dose not test if its a prime number so make sure they are. you can alsow specify a modular value n
. n
will be generated if not passed or incorrect. to generate just use, where p
and q
are the prime numbers:
key = rsa4py.PrivateKey(p, q)
if you want to generate with n
key = rsa4.py.PrivateKey(p, q, n)
Public Key
to generate a public key you can eather pass the modular value n
and the encription key e
. or you can generate it from a private key.
to generate from public key k
. use
publicKey = k.getPublic()
to get from n
and e
use:
publicKey = rsa4py.PublicKey(n, e)
usage
encription
encription can be done with both the Public and Private Keys. both methods work the same way. For a given key k
and a text t
the encripton works as followes.
msg = k.encript(t)
out will be a list of values of the valus of the encripted text.
decription
for decription you need to use the Private key. this works as follows. for a given private key k
, an encripted text out
, t
will be the decripted text
t = k.decript(msg)
message
during endcription and decription we used the variable msg
witch is a CritptoMessage
class witch is a subclass of a list
. it contains the entripted message as itself, an intager signature
witch is the authentication value of the message.
###saving messages###
to save a message use the following function where filename
is the name of the file to save to (no file extension) and msg
is the message to save
msg.save(filename)
you can also use somthing like pickle directly by for example:
pickle.dump(msg, open(f"{filename}.msg.p, "wb))
###loading messages###
loding is done using the loadMsg function. again filename
is the name of the file to load from.
msg = rsa4py.loadMsg(filename)
or using somthing like pickle directly:
msg = pickle.load(open(f"{filename}.msg.p", "rb"))
authentication
the library suports authentication of messages. this is done usind the senders private and public keys.
###signing###
to sign a messsage you have to use your own PrivateKey
p
and a message msg
msg.sign(p)
###authenticating###
when trying to figure out if a messages signature is correct you have to use the signatureCorrect
method. this is done using the PublicKey
k
of the sender (aka p.getPublic()
)
out = msg.signatureCorrect(k)
out will be a boolean value witch is true if the authentication was correct.
filed keys
saving
you can alsow save a key k
to a file and load them later using:
k.save(file)
where file is the string containing the filename and path (no extension). the extension will be ".rsa.p".
loading
to load a key again you have to run the function:
key = rsa4py.loadKey(file)
where file is the name of the file containining the key without extension.
instalation
to install rsa4py via pi just use
pip install rsa4py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file rsa4py-0.0.2.0.tar.gz
.
File metadata
- Download URL: rsa4py-0.0.2.0.tar.gz
- Upload date:
- Size: 85.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb5df82d95db993dd8aa2fc65c677248d68b9acc9de6b9af0a23faea2ef15e66 |
|
MD5 | fed4bf1e4b5dacfd0a0eecc9227c607e |
|
BLAKE2b-256 | f6d97473c6083af8c90369a21c9166512c0ccb68b5cfb7d4b12781a1329173b9 |