Hi, I would like to import and use in OpenSSL RSA key pairs generated by an other program.
This program can export public and private keys to PEM files, with X509 and PKCS#7 specifications. But, the private key doesn't contain Chinese Remainder Theorem factors, only the private exponent and the modulus. So, I'm able to encrypt a file with the public key : C:\openssl rsautl -encrypt -inkey pub.pem -pubin -in hello.txt -out hello.enc Loading 'screen' into random state - done But, trying to decrypt causes the following error : C:\openssl rsautl -decrypt -inkey priv.pem -in hello.enc -out result.txt Loading 'screen' into random state - done RSA operation error 2548:error:0306B067:bignum routines:BN_div:div by zero:.\crypto\bn\bn_div.c:213: I suppose the error comes from the fact that openssl.exe tries to use the CRT factors to decrypt the file. Could you confirm this ? And of course, is there any way to make works decryption with my keys ? Currently, I'm thinking about three possible solutions : 1) find a way to generates CRT factors from modulus and private exponent (but I don't know if it's possible) 2) could the use of the RSA C functions, instead of the openssl binary, solve the problem, because http://openssl.org/docs/crypto/rsa.html says "p, q, dmp1, dmq1 and iqmp may be NULL in private keys, but the RSA operations are much faster when these values are available." ? 3) and last, generate the keys with OpenSSL, but honestly I would really appreciate to not have to do that and continue to generate key pairs with my first program. An example of key pair is attached with this e-mail. And for those who knows, the first program is coded Java, the private key comes from the PrivateKey class and is exported to PEM file with the PemWriter class of BountyCastle. Thanks, JB
pub.pem
Description: Binary data
priv.pem
Description: Binary data