I have a task to get modulus and exponent of a given key and insert this as a #define in my STM32 firmware.
I've done this previously using a DER key and this forum helped me a lot. (Embedded a .der file into C code using makefile)
What I need is actually to create something like:
#define MODULUS { 0x00, 0xff ..... }
#define EXPONENT { 0x........}
I need to use modulus and exponent because that is what X-CUBE-CryptoLib for STM32 requires, instead of a DER KEY.
I'm trying to figure it out using this command:
$(shell openssl rsa -inform DER -text -noout < privatekey.der | awk 'BEGIN { printf "#ifndef _DER_H_\n#define _DER_H_\n/* Auto generated file. Do not modify! */\n#define DER_KEY {" } { for(i=1; i<=NF; ++i) printf " 0x" $$i ","; print "\\" } END { print "};\n#endif" }' > Core/Inc/der.h)
But the command above prints a bunch of info that I won't use, such as public exponent and some prime exponents. Also the whole field identification ("modulus:..." "private exponent:..." makes it complicated to handle this with the single awk loop I have.
Could anyone give me a hint on how I could get this task done?