Solving the Assignment in the OWASP WebGoat Crypto Basics Signature Lesson

This site utilizes Google Analytics, Google AdSense, as well as participates in affiliate partnerships with various companies including Amazon. Please view the privacy policy for more details.

So I’ve been playing around with the OWASP WebGoat project.

The WebGoat Logo

The WebGoat Logo

WebGoat is a web application with a Java Spring back-end. Its purpose is to teach - through a series of interactive lessons - vulnerabilities in web applications, particularly those with Java back-ends. As such, it is deliberately insecure.

I was chugging along with the lessons just fine until I reached the assignment on cryptographic signatures in the Crypto Basics section.

Screenshot of the Cryptographic Signatures Lesson in the Crypto Basics Section

Screenshot of the Cryptographic Signatures Lesson in the Crypto Basics Section

Now, I understand what cryptographic signatures are. They’re a way of verifying that data hasn’t been modified since it was signed. Typically it’s a hash of the data that has been encrypted using a private key and verifiable with a public key.

What confused me was what format they wanted the answer to be in.

For context, here’s the assignment:


Here is a simple assignment. A private RSA key is sent to you. Determine the modulus of the RSA key as a hex string, and calculate a signature for that hex string using the key. The exercise requires some experience with OpenSSL. You can search on the Internet for useful commands and/or use the HINTS button to get some tips.

Now suppose you have the following private key:


Then what was the modulus of the public key and now provide a signature for us based on that modulus

Ok, I’m a little confused. I know they want the modulus of the RSA as a hex string but what format do they want the signature in? Bits? Also a hex string? Maybe even a Base64 string - after all, one of the previous lessons covered Base64.

Let’s experiment. What happens if I click the post the answer without entering anything?

It turns out it outputs the following error: The modulus is not correct

Ok, let’s see if I can figure out the modulus (remember - as a hex string!) and see if it tells me anything different.

I want to use OpenSSL, however, since I’m running Windows, I don’t have it immediately available on the command line.

However, I’m running WebGoat in a Docker container. Which is in a Linux container. Which means I can go into the terminal of the WebGoat container and use OpenSSL. No extra installation required.

In case you’re wondering, here are the commands to run WebGoat in a Docker container:

docker pull webgoat/webgoat-8.0
docker run -p 8080:8080 -t webgoat/webgoat-8.0

Inside the terminal, I copied the key with some echo commands:

echo -----BEGIN PRIVATE KEY----- > private.key
echo _THE_PRIVATE_KEY_ >> private.key
echo -----END PRIVATE KEY----- >> private.key

And then ran the following openssl command to get the modulus:

openssl rsa -text -noout -in private.key

There’s quite a bit of output, but what I’m interested in is this first part:


That most certainly looks like hex code - I’m only seeing numbers and the letters a through f. But if I copy that as-is into the modulus input box, I get another The modulus is not correct error.

It turns out I need to remove those pesky colons and white spaces - so instead I insert the following:


This time I get a different error: The signature does not match the data (modulus)

Yay - now I’m halfway through! I just need to provide a signature based on that modulus.

So I put the modulus into a file like I did the key:

echo > mod.txt

And then try to sign the file like:

openssl dgst -sign private.key -sha256 -hex mod.txt

But when I paste the result (and just the hex bit) into the signature field, I just get another The signature does not match the data (modulus) message.

I even tried to convert the hex to a base64 string, or a binary string, and still got the same error. I even tried signing the modulus by piping it in instead of via a file, but it just gave me the same signature:

echo | openssl dgst -sign private.key -sha256 -hex

At this point, I have no idea if I’m doing the signature wrong (and if I am, please tell me what I’m doing wrong in the comments!) or if I’m simply not providing the right format that WebGoat wants.

It’s time to open up WebGoat and to figure this out.

Fortunately for me, I don’t have to extract WebGoat from the Docker container - the source code for WebGoat is available on GitHub.

As for where in the source code I need to look, WebGoat provides this useful bit of info in the log:

2022-06-09 21:43:26.429 DEBUG 23 --- [  XNIO-1 task-3] org.owasp.webgoat.crypto.CryptoUtil      : end verifyMessage
2022-06-09 21:43:26.429  WARN 23 --- [  XNIO-1 task-3] o.o.webgoat.crypto.SigningAssignment     : signature incorrect
2022-06-09 21:46:24.664 DEBUG 23 --- [  XNIO-1 task-5] org.owasp.webgoat.crypto.CryptoUtil      : start verifyMessage
2022-06-09 21:46:24.665 ERROR 23 --- [  XNIO-1 task-5] org.owasp.webgoat.crypto.CryptoUtil      : Signature verification failed Signature length not correct: got 384 but was expecting 256
at java.base/ ~[na:na]
at java.base/$Delegate.engineVerify( ~[na:na]
at java.base/ ~[na:na]
at org.owasp.webgoat.crypto.CryptoUtil.verifyMessage( ~[crypto-8.2.2.jar!/:8.2.2]
at org.owasp.webgoat.crypto.SigningAssignment.completed( ~[crypto-8.2.2.jar!/:8.2.2]

2022-06-09 21:46:24.666 DEBUG 23 --- [  XNIO-1 task-5] org.owasp.webgoat.crypto.CryptoUtil      : end verifyMessage
2022-06-09 21:46:24.666  WARN 23 --- [  XNIO-1 task-5] o.o.webgoat.crypto.SigningAssignment     : signature incorrect

The log leads me to - but more importantly to has a signMessage method that returns a String - a String that I suspect is in the format that the lesson wants the answer.

So I made a short Java program to output that String signature:

import java.nio.charset.Charset;
import java.util.Base64;

public class Sig {
    public static void  main(final String... args) throws Exception {
        final String message = _THE_MODULUS_AS_HEX_;

        final String privateKey = _THE_PRIVATE_KEY_;

        final PrivateKey key = getPrivateKeyFromPEM(privateKey);

        final Signature instance = Signature.getInstance("SHA256withRSA");

        //actual verification against signature
        final String signature = new String(Base64.getEncoder()


    public static PrivateKey getPrivateKeyFromPEM(String privateKeyPem) throws Exception {
        privateKeyPem = privateKeyPem.replace("-----BEGIN PRIVATE KEY-----", "");
        privateKeyPem = privateKeyPem.replace("-----END PRIVATE KEY-----", "");
        privateKeyPem = privateKeyPem.replace("\n", "").replace("\r", "");

        final byte [] decoded = Base64.getDecoder().decode(privateKeyPem);

        final PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(decoded);
        final KeyFactory kf = KeyFactory.getInstance("RSA");
        return kf.generatePrivate(spec);

And then copy-paste the signature into the answer text box, clicked on the button, and got the following message: Congratulations. You found it!

By the way, here’s the signature - in Base64. I don’t know what I needed to do to get this from OpenSSL:


Onto the next lesson!

2 comments for Solving the Assignment in the OWASP WebGoat Crypto Basics Signature Lesson

  • avatar for Steve Steve

    I had to use echo -n with the colon-less hex blurb in quotes, pipe it to what you have exactly with exception of the -hex, then pipe to base64

    So, echo -n “hex without colons and spaces” openssl dgst -sign private.key -sha256 base64

    **99% of this came from the hints as they probably thought most of us would have issues with this concept.


    Reply to This Thread

  • avatar for Andre Combrinck Andre Combrinck

    Thanks for the guidance. I was banging my head. I thought I’ll share the method that does not need find and replace in a separate text editor.

    openssl pkey -in lesson6.key -pubout -out public.key openssl rsa -in public.key -pubin -modulus -noout

    Copy the text after Modulus= to the first text box.

    echo -n “hex of modulus” openssl dgst -sign lesson6.key -sha256 base64 -w 0

    Reply to This Thread

Leave a Reply

Note that comments won't appear until approved.