How do I combine n and e to create a public key in RSA?
I have a 128 byte (1024 bit) modulus (in byte array format) and my exponent (also in byte array format). I need to create a 128 byte array representing the public key.
According to Wikipedia, "a public key consists of a modulus n and a public (or encryption) exponent e". But that doesn't tell me how to mix both.
What is the correct operation?
- n ^ e (will there be 128 bytes left?)
- just n?
- n followed by e?
- n added to e?
- something other?
source to share
There are many different formats for representing RSA public keys. One of the most common is PKCS # 1. RFC 3447 defines the public key format as
RSAPublicKey ::= SEQUENCE {
modulus INTEGER, -- n
publicExponent INTEGER -- e
}
In order to represent a key in this format, you need to apply DER ASN.1 encoding to this data structure.
Another choice is SubjectPublicKeyInfo, from RFC 3280:
SubjectPublicKeyInfo ::= SEQUENCE {
algorithm AlgorithmIdentifier,
subjectPublicKey BIT STRING
}
For RSA, the algorithm should be 1.2.840.113549.1.1.1 .
There are several other formats, such as those used for SSL.
source to share