两个64位的密文相乘后变成128位的密文,该密文还能别原来的私钥解密吗,在执行自己写的代码后一直解密失败,找不到问题所在了。代码如下:在倒数第六行,解密m4的时候一直解密不成功
-- coding: utf-8 --
import rsa
先生成一对密钥,然后保存.pem格式文件,当然也可以直接使用
(pubkey, privkey) = rsa.newkeys(512)
pub = pubkey.save_pkcs1()
pri = privkey.save_pkcs1()
load公钥和密钥
message = '18.234'.encode('utf-8')
m2='1.3'.encode('utf-8')
pubkey = rsa.PublicKey.load_pkcs1(pub)
privkey = rsa.PrivateKey.load_pkcs1(pri)
用公钥加密、再用私钥解密
```python
crypto = rsa.encrypt(message, pubkey)```
m2 =rsa.encrypt(m2,pubkey)
print(crypto)
print(m2)
```python
crypto = int.from_bytes(crypto, byteorder='little', signed=True)
m2 = int.from_bytes(m2, byteorder='little', signed=True)```
print(crypto)
print(m2)
m3=crypto*m2
print(m3)
```python
crypto = crypto.to_bytes(64, byteorder='little', signed=True)
m2 = m2.to_bytes(64, byteorder='little', signed=True)
m3 = m3.to_bytes(128, byteorder='little', signed=True)
print(crypto)
print(m2)
length=len(m3)
m4=m3[0:64]
m5=m3[64:length]
message = rsa.decrypt(crypto, privkey)
m2 = rsa.decrypt(m2, privkey)
m4 = rsa.decrypt(m4, privkey)
m5 = rsa.decrypt(m5, privkey)
print(message.decode('utf-8'))
print(m2.decode('utf-8'))```
print(m4.decode('utf-8'))
print(m5.decode('utf-8'))