Skip to main content

end-to-end client-server encryption

Project description

# NaniCrypt
> end-to-end client-server encryption
## About
NaniCrypt is a simple wrapper over AES and RSA to distribute best safe experience to end user.
Written in pure python and used libraries are also pure python.
## Installation
- Install it as a usual library:
`pip install nanicrypt`
- or clone from source and install dependencies
### Dependencies
- pyaes
- rsa
- (optional) requests

## Usage
Usage of NaniCrypt is pretty straightforward.
#### Client-side
```python
import nanicrypt
pub = "-----BEGIN RSA PUBLIC KEY-----..."
salt = "example app"
client = nanicrypt.ClientNaniCrypt(pub, salt)
data = {"example": True, "list": [1, 2, 3]}

encrypted = client.encrypt(data)
# send to server
server_rsp_decrypted = client.decrypt(server_rsp, encrypted.key)
```
#### Server-side
```python
import nanicrypt
priv = "-----BEGIN RSA PRIVATE KEY-----..."
salt = "example app"
server = nanicrypt.ServerNaniCrypt(priv, salt)
client_req = {"m": "some data", "k": "from client"}

client_req_decrypted = server.decrypt(client_req, client_sign)
# do something
response_encrypted = server.encrypt({"success": True}, client_req_decrypted.key)
# send back to client

```
#### Using built-in networking
```python
import nanicrypt
pub = "-----BEGIN RSA PUBLIC KEY-----..."
salt = "example app"
data = {"example": True, "list": [1, 2, 3]}
net = nanicrypt.NaniCryptNetworking(pub, "http://127.0.0.1/nanicrypt", salt)

server_rsp = net.make_request("example.php", data)
```

## Docs

### Classes
#### ClientNaniCrypt
##### Constructor:
`ClientNaniCrypt(pubkey, sign_salt)`
> `pubkey`: `str` or `bytes` - public rsa key
> `sign_salt`: (optional) `str` - sign salt. must be same on both client and server
##### Methods:
`.encrypt(data, key) -> ClientEncrypted` - encrypting data before sending
> `data`: `dict` - data to be encrypted. must only contain as key/value: `list/dict/bool/str`
> `key`: (optional) `bytes` - key for `data` to be encrypted. if not specified or is `None`, random will be generated

`.decrypt(data, key) -> dict` - decrypting server-sent data
> `data`: `dict` - parsed json sent from server.
> `key`: `bytes` - aes key used to encrypt payload

`.make_sign(payload) -> str` - used to create sign to validate requests
> `payload`: `dict` - encrypted client data.
#### ClientEncrypted
##### Constructor:
`ClientEncrypted(data, key, sign)` - container for client-encrypted data
###### Fields:
> `data`: `dict` - dict with encrypted data
> `key`: `bytes` - random (or not) key used to encrypt
> `sign`: `str` - autogenerated request sign
> `base64_key`: `str` - base64-encoded `.key`
> `json`: `str` - json representation of `.data`
> `sign_header`: `dict[str, str]` - dictionary with `.sign` for using in `requests`

#### ServerNaniCrypt
##### Constructor:
`ServerNaniCrypt(privkey, sign_salt)`
> `privkey`: `str` or `bytes` - private rsa key
> `sign_salt`: (optional) `str` - sign salt. must be same on both client and server
##### Methods:
`.decrypt(data, sign) -> ServerDecrypted` - decrypting user-sent data
> `data`: `dict` - parsed json sent from client.
> `sign`: (optional) `str` - request signature

`.encrypt(data, key) -> dict` - encrypting data before sending back
> `data`: `dict` - data to be encrypted. must only contain as key/value: `list/dict/bool/str`
> `key`: `bytes` - key for `data` to be encrypted. MUST be same as for decryption.

`.make_sign(payload) -> str` - used to create sign to validate requests
> `payload`: `dict` - encrypted client data.

`.check_sign(payload) -> bool` - used to check sign to validate requests
> `payload`: `dict` - encrypted client data.

#### ServerEncrypted
##### Constructor:
`ServerEncrypted(data, key, sign)` - container for client-encrypted data
###### Fields:
> `data`: `dict` - dict with encrypted data
> `key`: `bytes` - random (or not) key used to encrypt
> `sign_valid`: `bool` - whether `sign` was valid
> `json`: `str` - json representation of `.data`
> `base64_key`: `str` - base64-encoded `.key`

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
NaniCrypt-0.1.0.tar.gz (5.6 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page