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?

+2


source to share


3 answers


You cannot create an array like this. The "public key" has two parts: an indicator and a module. They are separate numbers that must be kept separate as they are needed for later encryption and decryption. Although yours n

is 1024 bits, the shared key should generally be longer.



+2


source


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.

+3


source


"N followed by e" is probably the closest thing to what you want. But if you intend to interact with any other RSA based system, you should consult this system documentation to see how they expect public keys to be formatted.

+1


source







All Articles