-1
$\begingroup$

I have an encoded file and a public.pem file. Is it possible to decode the file using the public.pem file or do I have to start looking at private keys?

I tried https://github.com/Ganapati/RsaCtfTool with no luck. The public key (pem) is as below

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjHDiqVkO1umD2/Tm20Wt
LpyBXGoIk4Pczeqjwz7/kwYLnQI7VlAzgjC9jD1dX80Z+kLOr5wHIDdfNK55nC/q
ux/g7xVt0YKMl5yzObHUgX0YUi//8k2a5YfidxWoX77B7GfuBKx0efEsM7p+7cYT
z7OVKFdRIvKATMGsYlWOPT9b97OtTQjtZKyhAtL1PdbfqKCCxRzqvj1OthtHbB+b
4AJG4MI2IHJQ0LHyj83md3iIMQSMZxwe8JsWQs3jW7W1xRDWjDsKn1799kPTTgG3
GtVrO6J38HN5t5dk8ZNa7duh9phRyEBQbo2lH/tYqUBKeJ3v/dA0BhQVMdZe5m8R
uQIDAQAB
-----END PUBLIC KEY-----
$\endgroup$
1
  • $\begingroup$ What is the origin of this Q? $\endgroup$
    – kelalaka
    Commented Nov 27, 2021 at 12:18

2 Answers 2

3
$\begingroup$

Adding on to the above, the modulus and public exponent can be extracted from the public.pem. The public exponent e is 10001.

It turns out that this is a constructed modulus which is very weak and was not generated using recommended security guidelines.

The 2048 bit, 617 decimal digit modulus N=pq can be factored immediately because it is a square. That's right p=q and N = p^2.

phi(N) = p(p-1)

The method to find d the private exponent when e, p and q are known has been shown many times on this forum. Then the file can be decrypted.

$\endgroup$
4
  • 1
    $\begingroup$ Good catch on the square, but phi(p^2) is NOT (p-1)x(p-1). See en.wikipedia.org/wiki/… . $\endgroup$ Commented Nov 28, 2021 at 5:02
  • $\begingroup$ Corrected. Thanks. The error could have led someone down a time consuming path. $\endgroup$ Commented Nov 28, 2021 at 15:15
  • $\begingroup$ Any advice on a good question/answer that would highlight how to find the numbers @MostlyResults $\endgroup$
    – pee2pee
    Commented Dec 3, 2021 at 21:23
  • $\begingroup$ If your ctf question insists that a file or text can be decrypted from the public.pem even though p and q are the same, look at the answer to the second question in this link: crypto.stackexchange.com/questions/52240/… $\endgroup$ Commented Dec 5, 2021 at 14:30
2
$\begingroup$

Is it possible to decode the file using the public.pem file

No.

or do I have to start looking at private keys?

Yes.

RSA is an asymmetric encryption algorithm. That means that its keys come in pairs, containing a public key and a private key, and that data encrypted with the public key can only be decrypted with the private key.

$\endgroup$
2
  • 2
    $\begingroup$ Dr. Spock would qualify "data encrypted with the public key can only be decrypted with the private key" as technically incorrect. Poorly thought RSA padding (as common in CTFs and introductions to RSA, including textbook RSA) may allow decryption without private key. So can access to a decryption device in Bleichenbacher's attack on RSAES-PKCS1-v1_5. And in all RSA encryption modes of PKCS#1, any of multiple private keys allow decryption. $\endgroup$
    – fgrieu
    Commented Nov 27, 2021 at 10:46
  • $\begingroup$ Thanks - it as indeed for a CTF and was possible $\endgroup$
    – pee2pee
    Commented Nov 29, 2021 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.