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-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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With