I need to extract modulus, private exponent, public exponent, primes, etc. from an RSA private key given in PEM format. This is for an embedded system where I cannot install any crypto or RSA libraries on the target system, so everything should be done in native C. Any pointers to existing code or hints how this is efficiently done would be appreciated.
Parsing a PEM key in C without extra libraries
1.6k Views Asked by Peter B. At
2
There are 2 best solutions below
Related Questions in C
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in RSA
- Are there poor practices in this use of python cryptography package to generate RSA keypair?
- OpenSSL3.0 RSA Signature Verification in C
- Mbed TLS: in-place en-/decryption for OAEP doesn't seem to work
- Converting C# RSA private key into a form BCrypt can understand
- RSASSA-PSS signature verification fails dues to padding with mbedtls but succeeds in Python
- Encrypt and Decrypt File Using PHP
- Expo: RSA decrypt huge performance drop after updating from SDK 47 to 50
- regex for [2,4,p^t,2p^t] where p is prime and t is any positive integer
- Missing Private Key after updating Node
- Cont:Use a RSA public key to generate the corresponding private key in OpenSSL?
- RSA decrypt failed
- Unable to load RSA-PSS public key in iOS using SecKeyCreateWithData
- Sign data with RSA
- PyInstaller - ModuleNotFoundError: No module named 'rsa'
- How can I generate an x509 RSA-PSS certificate with openssl whose trailer field contains the value 0xBC meet the RFC8017
Related Questions in PEM
- Can't upload public.pem file for Integrity Api on Google Play Console
- Accidentally changed the permissons of .ssh and now cannot access ec2 instance
- Why can't I convert .pem to .p12 file without splitting it?
- How to convert JWK to PEM format in Delphi?
- Ruby check an apple pem
- Invalid argument: key error in Utilities.computeRsaSha256Signature
- PEM auto discovery not working for community postgres 15
- Angular doesn't seem to function under HTTPS; it immediately returns a white screen. It loads indefinitely until the page crashes
- How to convert DER encoded certificate to PEM?
- Jest (with ts-jest) displays wrong line number when pem library is added to TypeScript project
- How to extract/create/recover a private .key file with ECPARAM from .pem or .csr file?
- Convert a hex ECDSA private key to PEM format (OpenSSL)
- Karate API call with .pem file
- Android pem cert inside keystore
- Permission Denied 13 during Soap client method invoke. Python Zeep .pem
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
PEM file contains der encoded RSA Private Key in base64 format.
First you have to base64 decode it to get the original der encoded bytes. Then you have to parse the der encoded data.
As suggested by Lie Ryan, you can statically link some C libraries to do this. Or you can refer to the source codes of an existing library and write your own parser to do that.
For a light-weight library, I recommend looking at libtomcrypto's der routines in case you are going to write your own parser.
The same library also contains functions for base64 encoding and decoding.