login about faq

Hi, I'm generating a 4096 bit RSA key. The process succeed and I use (IOS but same result on C#) the exportPublicKey. I after add the KEY into a Public Key object (CkoPublicKey) using LoadXML again succeed. Now I extract the publickey from the newly generated CkoPublicKey object using the GetXml and I got a different key.

any idea why? I suppose to get the same key.

Here the code CkoRsa rsa = [[CkoRsa alloc]init]; CkoPublicKey PubKey = [[CkoPublicKey alloc]init];

BOOL success;

......

rsa.EncodingMode = @"base64"; success = [rsa GenerateKey: [NSNumber numberWithInteger: 4096]];

NSString *Xml = [rsa ExportPublicKey]; success = [PubKey LoadXml: Xml];

NSString *Xml1 = [PubKey GetXml];

// NOW XML and XML1 are different.

asked Sep 22 '14 at 16:04

Luigius's gravatar image

Luigius
6125


There is actually no problem. The Modulus of the public key appears to be different, but in fact it is not. The Modulus is an extremely large positive integer. (You might hear it referred to as a "BigNum" or a "BigInt".) Assuming the same byte ordering, an integer can be represented with any number of leading 0 bytes, and it is still the same integer. For example, the number 4 is represented in a 4-byte integer as 0x00000004. It is represented as a 2-byte integer as 0x0004. Both are the same integer.

If you base64 encode different representations of the same integer, the result is that the base64 encoding looks entirely different.

If you decode from base64 the Modulus in each case, and then encode each to a hex representation, you'll find something like this:

Modulus1:  CD900A0F53B6E...
Modulus2:  00CD900A0F53B6E...

One has a harmless leading 0 byte, but it is still the same Modulus (it just looks completely different when base64 encoded.

link

answered Sep 24 '14 at 10:55

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×48
×6

Asked: Sep 22 '14 at 16:04

Seen: 1,233 times

Last updated: Sep 24 '14 at 10:55

powered by OSQA