# Python 实现RSA、AES加解密

项目立意是为了解除python多数库只能使用公钥加密的限制。



## 示例


### RSA加解密
```python
from RealCrypto import Rsa


pyrsa = Rsa()

pub_key = """
-----BEGIN RSA PUBLIC KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
-----END RSA PUBLIC KEY-----
"""

data = " "

ret = pyrsa.pub_decrypt(bytes.fromhex(data), pub_key)
print(ret)

ret = pyrsa.pub_encrypt("23342321",pub_key)
print(ret)
```


### AES加解密
```python
from RealCrypto import Aes,AesType

pyaes = Aes()

key = "1234657887654321"
iv = "1236547896325418"
plaintext = "just a test"
ret = pyaes.encrypt(plaintext,AesType.evp_aes_128_cbc, key,iv)
ret = pyaes.decrypt(ret,AesType.evp_aes_128_cbc, key,iv)
assert plaintext,ret.decode("utf-8")

```


### Hash算法

```python
teststr = "just a test"

# 字符串hash
ret = hash.md5(teststr)
print(ret.hex())

ret = hash.sha256(teststr)
print(ret.hex())


filepath = "test.txt"
# 文件hash
ret = hash.md5withfile(filepath)
print(ret.hex())

ret = hash.sha256withfile(filepath)
print(ret.hex())
```
