Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Get rsa.decrypt working #17

Merged
merged 4 commits into from
Feb 23, 2023
Merged

fix: Get rsa.decrypt working #17

merged 4 commits into from
Feb 23, 2023

Conversation

cpswan
Copy link
Member

@cpswan cpswan commented Feb 23, 2023

rsa.decrypt was always failing as this test always returned true:

if cleartext[0:2] != b'\x00\x02':

It seems that the leading characters for the cleartext we're getting are b' \x02' - a space instead of a null

This isn't happening at the padding stage before encryption, which is correct. But I've not been able to track down where that b'\x20' is creeping in.

- What I did

Allow the test to pass when it finds b' \x02' (as well as b'\x00\x02')

Also added pycache to .gitignore

- How I did it

Looked at raw cleartext to see why the test was failing and observed a leading space rather than the null that should be there.

- How to verify it

import sys
import ubinascii
sys.path.append('./lib')
from pem_service import get_pem_parameters, get_pub_parameters, get_pem_key
from third_party import rsa
encryptpub='A_PEM_encoded_RSA_public_key'
encryptpriv='A_PEM_encoded_RSA_private_key'
pubKey = get_pub_parameters(encryptpub)
print(pubKey)
rsapub = rsa.PublicKey(pubKey[0], pubKey[1])
privKey = get_pem_parameters(get_pem_key(encryptpriv))
print(privKey)
rsapriv = rsa.PrivateKey(privKey[0], privKey[1], privKey[2], privKey[3], privKey[4])
enchello = rsa.encrypt(b'hello world', rsapub)
print(rsa.decrypt(enchello, rsapriv))

- Description for the changelog

fix: Get rsa.decrypt working

@cpswan cpswan merged commit 88954bf into trunk Feb 23, 2023
@cpswan cpswan deleted the cpswan_rsa_decrypt branch February 23, 2023 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants