Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

I am generating RSA Public and Private keys with node.js instead of reading them from pem/crt files as I can hide them inside a private object using this module https://www.npmjs.org/package/private

this node.js module https://www.npmjs.org/package/keypair puts text in front and at the end of each public and private (-----BEGIN RSA PUBLIC KEY-----)

Edit: forget this question (thanks D.W.) Is this they way they should look or can I remove the text?

var keypair = require('keypair');

var pair = keypair();
console.log(pair);

outputs

{ public: '-----BEGIN RSA PUBLIC KEY-----\r\nMIGJAoGBAM3CosR73CBNcJsLv5E90NsFt6qN1uziQ484gbOoule8leXHFbyIzPQRozgEpSpi\r\nwhr6d2/c0CfZHEJ3m5tV0klxfjfM7oqjRMURnH/rmBjcETQ7qzIISZQ/iptJ3p7Gi78X5ZMh\r\nLNtDkUFU9WaGdiEb+SnC39wjErmJSfmGb7i1AgMBAAE=\r\n-----END RSA PUBLIC KEY-----\n',
  private: '-----BEGIN RSA PRIVATE KEY-----\r\nMIICXAIBAAKBgQDNwqLEe9wgTXCbC7+RPdDbBbeqjdbs4kOPOIGzqLpXvJXlxxW8iMz0EaM4\r\nBKUqYsIa+ndv3NAn2RxCd5ubVdJJcX43zO6Ko0TFEZx/65gY3BE0O6syCEmUP4qbSd6exou/\r\nF+WTISzbQ5FBVPVmhnYhG/kpwt/cIxK5iUn5hm+4tQIDAQABAoGBAI+8xiPoOrA+KMnG/T4j\r\nJsG6TsHQcDHvJi7o1IKC/hnIXha0atTX5AUkRRce95qSfvKFweXdJXSQ0JMGJyfuXgU6dI0T\r\ncseFRfewXAa/ssxAC+iUVR6KUMh1PE2wXLitfeI6JLvVtrBYswm2I7CtY0q8n5AGimHWVXJP\r\nLfGV7m0BAkEA+fqFt2LXbLtyg6wZyxMA/cnmt5Nt3U2dAu77MzFJvibANUNHE4HPLZxjGNXN\r\n+a6m0K6TD4kDdh5HfUYLWWRBYQJBANK3carmulBwqzcDBjsJ0YrIONBpCAsXxk8idXb8jL9a\r\nNIg15Wumm2enqqObahDHB5jnGOLmbasizvSVqypfM9UCQCQl8xIqy+YgURXzXCN+kwUgHinr\r\nutZms87Jyi+D8Br8NY0+Nlf+zHvXAomD2W5CsEK7C+8SLBr3k/TsnRWHJuECQHFE9RA2OP8W\r\noaLPuGCyFXaxzICThSRZYluVnWkZtxsBhW2W8z1b8PvWUE7kMy7TnkzeJS2LSnaNHoyxi7Ia\r\nPQUCQCwWU4U+v4lD7uYBw00Ga/xt+7+UqFPlPVdz1yyr4q24Zxaw0LgmuEvgU5dycq8N7Jxj\r\nTubX0MIRR+G9fmDBBl8=\r\n-----END RSA PRIVATE KEY-----\n' }

Public key is real short!

I found this code

function bitSize(n){return n.toString(2).length;}

If i give the pub key padding like

1001 0011 

or some other random repetition of the same byte until the public key is the same length as the private key. Will that be acceptable padding? I would have to protect my prime numbers with this kind of padding, true?

If I did add padding how would the private key have any relation to the padded public (Could it still decrypt?)

share|improve this question
    
What are you trying to achieve? What problem are you trying to solve? What's wrong with leaving that there? It is part of the standard format: see PGP and OpenPGP. –  D.W. Jun 20 at 21:24
    
I was making my question more to the point while you were commenting, thank you for the input –  BENZ.404 Jun 20 at 21:56
    
I still don't understand what you are trying to achieve. Why are you contemplating adding padding? What problem are you trying to solve? Why is the standard output problematic or unacceptable? What are your requirements? Also, when editing, please make sure the edited question stands on its own (don't add "edit: never mind this part", just delete the part that isn't relevant, and make it a good question on its own). We have a revision history, so you don't need to preserve prior versions. Make it something that'll be a great question for someone who encounters this for the first time. –  D.W. Jun 20 at 22:58
    
I tried really hard thinking tonnes for that question! I'm of the understanding that padding should be added to the public key else someone would be able to guess the two primes used to generate the keys, thus exposing the root cert –  BENZ.404 Jun 20 at 23:18
    
Also I thought it would be rude of me not to acknowledge your input or to just remove that part as it would make your comment not make sense. –  BENZ.404 Jun 20 at 23:20
show 1 more comment

1 Answer 1

up vote 3 down vote accepted

There is no need to manually add padding to the RSA public key.

Normally we'd expect the library to do whatever is needed to make key generation secure. You shouldn't need to do manual tweaks to the public key it produces. If the library doesn't do that, the library sucks; throw it away and get a better one.

And, for this specific case, no padding is needed during RSA key generation. There's no need to add any padding to the RSA public key. Depending upon how the private key is represented, the private key will often be of different length than the public key, so this is not something to worry about.

share|improve this answer
    
+1 you've made it clear to me. I think I'm getting confused with certificates and message hashes –  BENZ.404 Jun 21 at 0:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.