from ufastrsa.rsa import RSA, genrsa
def main():
bits = 512
print("RSA bits", bits)
r = RSA(*genrsa(bits, e=65537))
if r:
print("RSA OK")
data = b"a message to sign and encrypt via RSA"
print("random data len:", len(data), data)
assert r.pkcs_verify(r.pkcs_sign(data)) == data
print("pkcs_verify OK")
assert r.pkcs_decrypt(r.pkcs_encrypt(data)) == data
print("pkcs_decrypt OK")
if __name__ == "__main__":
main()
I copied https://github.com/dmazzella/ucrypto/tree/master/modules/ufastrsa and https://github.com/dmazzella/ucrypto/blob/master/modules/functools.py into
lib
and ran a slightly modified version of the example from the README:Thank you for the straightforward solution! xref https://github.com/orgs/micropython/discussions/10048#discussioncomment-4202935