0
votes

I am trying to learn about RSA encryption/decryption and it makes sense so far but I don't really understand how the public/private keys are generated and how they encrypt/decrypt.

For example, I generate a 1024-bit public/private key:

Public:

MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCCexd/+nDyyxOVsieqc4c6aC4wHPRi4Nsw0l7hy8XFDOWQiPxBTgeqYtWI2fVBp0J0yHNpibG893W5Ex2UfYUPf8Yru5J9Hr3yHveX1mzJOPedPTq3pg+SKpWGb9oqy76ucFyYM/Rat0IfqotUQSOV79sz1uCbDw1+2VA8klspmwIDAQAB

Private:

MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAIJ7F3/6cPLLE5WyJ6pzhzpoLjAc9GLg2zDSXuHLxcUM5ZCI/EFOB6pi1YjZ9UGnQnTIc2mJsbz3dbkTHZR9hQ9/xiu7kn0evfIe95fWbMk49509OremD5IqlYZv2irLvq5wXJgz9Fq3Qh+qi1RBI5Xv2zPW4JsPDX7ZUDySWymbAgMBAAECgYAnbUBlmGxmwPxTAHlB5RTYjkBeo3EpK56v+vFWszc4WrRHX00yAn0IfELfzlRwmTTYivVsz4GYgwHcga0vgFojLRTmynUNPHD/X64qBRWn7EwaQbjfU9w+xYUpNlJLSlXE9CJnoH/2dN+8zYs7VfhvrW5H3FYvs1DZzD0xe7Bf0QJBAMQBVfY5NtqFW/U8fesDFlwQ6St3Yt9+DbrC418AxxTvvkedQ5QoMo7T1g6VEfisK3b9B23V9q1Rl7XkexDAzDMCQQCqa13aMIteoOmc9UqCnXxIx4qWfH0cxf5/7l6b/hHCdIH3wtZCwHibWjCQukcTlWy/wwxUYhG29O/TCfOGDUT5AkAs8fF4SJ5fdX0kuv5UyZxy+B2/rdyqSwly7gWdX1xHXMJRQaqhaqZNQh4vsdcxIqnE2zi84vdxvuf++amOqecpAkBUCcooVJQFwBgzvIpXys2FHlFrUExqKgEMmUGybyHW4JlO0pfSJxPSmDEmzZVLRP5xuf+UhR/zNuolCd07F8QRAkAk1cg2PERmdk4CwOmxGE2z0PPpUtOFYD+lRtKwlBErCATqp2BBDW7DbhhNR5kRN538KwOpgVxZloTPoiujqVUz

And encrypt my message:

SN/3/es3RCRSp3s8zY/Uyg4Itwk5eELkVKU1OX00EBRixXHYFF/+96+QTxfC7G4HIsKqH2PNwAPPkg0OBzTMjP2GzSdVIkhV4WDKYWXjiPRu36aH/D5CMEY09d3oHlE//nTgI4dJ5XuZw9/e3UwgfMB+gJskIlJ1sfZ6k3hU8uY=

How did the RSA generator create these keys? How did it encrypt my text message? And how would it go about decrypting that encrypted message with these keys? What does that code look like?

(Note: I'm not using these particular keys for anything)

1
@tkausl Do you know how they use those numbers to encrypt/decrypt the message? I guess I just don't understand how text relates to numbers since it doesn't look like hex or anythingMrGVSV

1 Answers

0
votes

It sounds like your confusion stems from the fact that most RSA examples you see online work with (very large) numbers versus binary data or text.

Recall that, under the hood, computers only really work with 1's and 0's. If we implemented the RSA algorithm for numbers, we're actually just implementing an abstraction layer over a bunch of binary.

Text is also represented as binary. So we can easily convert between these.

For example, the word "Test", when encoded using UTF-8, looks like this in binary:

01010100 01100101 01110011 01110100

If we convert this binary sequence to a number (UInt32), we get 1415934836 - which would be suitable (but not secure) for use with an RSA example like the one demonstrated on wikipedia.