Stack Exchange Network
Stack Exchange network consists of 183 Q&A communities including
Stack Overflow
, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It only takes a minute to sign up.
Sign up to join this community
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
If I create an RSA of 4096 bits, what would be the range of the length in bytes of the public key in DER format?
Also, will the private key always be exactly 4096 bits (512 bytes)? Does the public key length depend on the actual length of the private key, or the length you specified (4096)?
$\begingroup$
You say DER, but you tag PGP which doesn't use DER -- and whose publickey block includes a lot of things beyond the RSA values (n,e). The DER encoding of a
PKCS#1
RSA publickey of 4096 bits with a conventional e of 65537 (default at least for openssl and Java) is
30 82 02 0a 02 82 02 01 (n with leading 00) 02 03 01 00 01
with a total length of 526 octets. The DER encoding of a generic SubjectPublicKeyInfo which is always used in X.509 certificates and often in other places (including openssl and Java) adds an outer SEQUENCE and AlgorithmIdentifier and a wrapping BIT STRING giving a total length of 550 octets. If you mean something else, specify it more clearly.
For the private exponent see RSA: Most significant key bit always 1? .
But if you are concerned about the encoding of a private key, that is much more than just the exponent and (possibly) modulus; see https://stackoverflow.com/questions/5403808/private-key-length-bytes . In addition the privatekey is often encrypted, which usually expands the encrypted value and adds metadata about the encryption.
If you have a question about a particular key encoding with a particular program or protocol/format, you need be much more specific.
$\begingroup$
$\endgroup$
–
Thanks for contributing an answer to Cryptography Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.