I\'ve generated a key with openssl by using the following command
openssl genrsa 1024
I\'ve got the following result
-----BEGI
Hi I've tested all 6 private keys you provided in EDIT with this command
$ openssl rsa -check -in privkey
and all of them returns RSA key ok
. Except the first one, it returns RSA key error: n does not equal p q
.
My answer to your question
Why the hell N is not equal to p * q ?
is: there's no way N is not equal to p*q. The first key has probably been modified, or has been changed during transmission, so it doesn't pass the rsa check test. Digging into the openssl source code, we can see that openssl genrsa
command is carried out by
int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb)
in /crypto/rsa/rsa_gen.c
. At ln:289, the modulus n
is calculated with
/* calculate n */
if (!BN_mul(rsa->n,rsa->p,rsa->q,ctx)) goto err;
which means n=p*q. You should look for other possibilities that cause your problem, rather than casting doubt on genrsa command.