https://github.com/loopyme/loopycryptor
https://github.com/loopyme/loopycryptor
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/loopyme/loopycryptor
- Owner: loopyme
- Created: 2019-12-31T07:09:18.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-25T07:03:18.000Z (almost 6 years ago)
- Last Synced: 2025-06-02T22:58:53.773Z (7 months ago)
- Language: Python
- Size: 5.53 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# loopyCrypto
Install it with `pip install loopyCrypto`
## Introduction
What I've done here is wrap part of `pycryptodome` and `pickle` functions up with a 'pythonic' interface, which is easy to use. What's more, it can encrypt **any kinds of python objects**, handle it properly and gives the output of the given type.
In short, I am trying to make a Cryptor that can help me as much as possible not to think about `bytes`, `string`, `byte boundary` and so many problems when I am trying to build a encrypted chat room.
## Docs
It's [here](http://api.loopy.tech/loopyCrypto/)
## Examples
- RSA
``` python
import loopyCryptor
# generate a pair of key
public_key, private_key = loopyCryptor.generate_RSA_key()
# encrypt
obj = [123,"HELLO",None,{"How are you?":b"I am fine and you?"}]
cipher_byte = loopyCryptor.RSA_encrypt(obj,public_key)
# decrypt
decrypt_obj = loopyCryptor.RSA_decrypt(cipher_byte,private_key)
# result
print(decrypt_obj)
print(decrypt_obj==obj)
print(list(map(type, decrypt_obj)))
# [123, 'HELLO', None, {'How are you?': b'I am fine and you?'}]
# True
# [, , , ]
```
- AES
``` python
import loopyCryptor
# generate a key
AES_key = loopyCryptor.generate_AES_key()
# encrypt
obj = [123,"HELLO",None,{"How are you?":b"I am fine and you?"}]
cipher_byte = loopyCryptor.AES_encrypt(obj,AES_key)
# decrypt
decrypt_obj = loopyCryptor.AES_decrypt(cipher_byte,AES_key)
# result
print(decrypt_obj)
print(decrypt_obj==obj)
print(list(map(type, decrypt_obj)))
# [123, 'HELLO', None, {'How are you?': b'I am fine and you?'}]
# True
# [, , , ]
```
- [Here](https://github.com/loopyme/chat_room/tree/loopyme) is an example of using `loopyCrypto` to build an Encrypted Chat Room.
- The following code is how do I use it:
```python
from loopyCryptor import encrypt, decrypt, generate_AES_key
my_obj = [1,2,3] # some object i want to save
key_pair = generate_RSA_key(set_default=True)
with open("./my_obj","wb") as f:
f.write(encrypt(my_obj, method = "RSA"))
# when I want to use it:
with open("./my_obj","rb") as f:
decrypt_obj = decrypt(f.read(), method = "RSA")
```