views:

123

answers:

4

Hello :)

I have a 128 byte (1024 bit) modulus (in a byte array format) and my exponent (also in a byte array format). I need to create a 128 bytes byte array representing the public key.

According to Wikipedia, "The public key consists of the modulus n and the public (or encryption) exponent e." But that doesn't tell me how to mix both.

What is the right operation to do?
-n^e (will that stay 128 bytes long?)
-just n?
-n followed by e?
-n added to e?
-something else?

Thank you :)

+1  A: 

Here is a link to a simple enough explanation.

Enjoy.

Eran Betzalel
+1  A: 

There are many different formats to represent RSA public keys. One of the more wide-spread ones is PKCS#1. In RFC 3447, the definition of the public key format is given as

  RSAPublicKey ::= SEQUENCE {
      modulus           INTEGER,  -- n
      publicExponent    INTEGER   -- e
  }

To represent a key in that format, you need to apply the ASN.1 DER encoding to this data structure.

Another choice is the 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 the ones used for SSL.

Martin v. Löwis
+1  A: 

You won't be able to create such an array. The "public key" has two parts: the exponent and the modulus. They are separate numbers that must be kept separate, since both are needed to perform encryption and decryption later on. Although your n is 1024 bits, the public key altogether is necessarily longer.

VoteyDisciple
+1  A: 

"N followed by e" is probably closest to what you want. But if you intend to interoperate with some other RSA-based system, you should consult that system's documentation to see how they expect public keys to be formatted.

Jim Lewis