2

I'm learning about RSA cryptography, so I must understand about ke length. Here, I found explanation about key length means.

There said:

When we say a "1024-bit RSA key", we mean that the modulus has length 1024 bits, i.e. is an integer greater than 2^1023 but lower than 2^1024. Such an integer could be encoded as a sequence of 1024 bits, i.e. 128 bytes.

What I've got from there, 1024 bit key means the key has 1024 binary number sequence int it.

We all know, 1 byte = 8 bits. So, 1024 bits = 128 bytes. Okay, it's in binary. How about in character?

According to ASCII binary code here, each character has 8 bits binary number. So, in my mind, if key has 1024 bit length, it means the key contains of 1024/8 = 128 characters. So, I created a java program to generate prime number that has 128 numbers length. So far, the program works well.

But again, I rethought the real meaning of RSA 1024-bit. So, I googled and found this. I tested it and I get that the bit length of public key modulus is 1024. But, the public key has 309 numbers length.

Now, I really confuse.

My question: what's the real means of 1024-bit key length in RSA? As I thought or as I found here?

Community
  • 1
  • 1
Speaky
  • 185
  • 1
  • 3
  • 15
  • Do you know what is binary and decimal representation of number and relation between them? – Oleg Estekhin May 07 '14 at 07:49
  • @OlegEstekhin Do you mean how to convert decimal to binary number and vice versa? – Speaky May 07 '14 at 08:13
  • 4
    Yes. The number that has 1024 digits in base 2 (binary) will have 128 digits in base 256, 256 digits in base 16 (hexadecimal) and about 309 digits in base 10 (decimal). – Oleg Estekhin May 07 '14 at 08:16
  • @OlegEstekhin I'm not so familiar with hexadecimal, but I know the relation between binary and decimal. So, what's the priority? In base 2 or base 10? – Speaky May 07 '14 at 08:25
  • 2
    It **does not matter**, it is the same number, just written differently. – Oleg Estekhin May 07 '14 at 08:47
  • base10 for a RSA key printout... what a shame java... what a shame... :-) – Gianluca Ghettini May 07 '14 at 08:51
  • 1
    Characters ≠ decimal digits. When you calculate "1024/8 = 128 characters" then these characters/bytes are allowed to have any possible value in the range 0...255 and not only the 10 decimal ASCII characters. – Perseids May 07 '14 at 09:09

2 Answers2

1

The example saves the key as Object Stream, which is java serialized object stream, it has some metainfo about javatypes and special format to encode binary data. To see genuine size of the number try "pub.getModulus().bitLength()". For me it prints 1024.

kan
  • 28,279
  • 7
  • 71
  • 101
  • 1
    Any explanation why "-"? Or the question is about number representation? Then the question is completely unrelated to RSA, java and encryption and @Speaky should just learn basics of computing. E.g. start here: http://en.wikipedia.org/wiki/Integer_%28computer_science%29 – kan May 07 '14 at 09:31
1

The important parameter is "greater than 2^1023". This means, the raw RSA encryption algorithm can represent arbitrary numbers from 0 to 2^1013-1, but not numbers greater or equal to the modulus. By Key Design the Modulus is the product of two different prime numbers and will never meet a power of 2, like 2^1024.

So the maximum number of bits you can represent is key-length-1, which are floor((key length -1)/8) complete bytes; in the best case you loose one bit of the key length.

As the PKCS-standard for mapping text to numbers considers complete bytes, you always need one more byte for representing the equivalent number; for a 1024-bit-key the maximum length of text to be encoded is 127 bytes.

The other number "309 bytes" comes from the X.509-Standard for storing/exchanging keys, a dialect of the ASN.1-Protocol; it includes RSA-type information, the modulus and the public exponent.

user207421
  • 305,947
  • 44
  • 307
  • 483
Sam Ginrich
  • 661
  • 6
  • 7