Hello, > I've tested it and it looks good. I get back the values I have set. > > Frank Wockenfuß > > -----Ursprüngliche Nachricht----- > Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Marek Marcola > Gesendet: Mittwoch, 1. August 2007 11:18 > An: openssl-users@openssl.org > Betreff: Re: AW: RSA_public_decrypt problem > > Hello, > > It should be > > > > pRSA->n = BN_bin2bn( pPublicModulus, nPublicModulusLength, NULL ); e = > > pRSA->BN_bin2bn( pPublicExponent, nPublicExponentLength, NULL ); > After that, you may try: > bn_hex = BN_bn2hex(pRSA->n); > printf("n: %s\n", bn_hex); > free(bn_hex); > bn_hex = BN_bn2hex(pRSA->e); > printf("e: %s\n", bn_hex); > free(bn_hex); > > to check that you have good big numbers. > > Best regards, > -- > Marek Marcola <[EMAIL PROTECTED]> Simple test program attached, hope this helps.
Best regards, -- Marek Marcola <[EMAIL PROTECTED]>
#include <stdio.h> #include <string.h> #include <openssl/ssl.h> #include <openssl/rsa.h> #include <openssl/err.h> #include <openssl/rand.h> #include <openssl/bn.h> int print_hex(unsigned char *buf, int len) { int i; int n; printf(" "); for (i = 0, n = 0; i < len; i++) { if (n > 7) { printf("\n "); n = 0; } printf("0x%02x ", buf[i]); n++; } printf("\n"); return (0); } int log_ssl(void) { char buf[256]; u_long err; while ((err = ERR_get_error()) != 0) { ERR_error_string_n(err, buf, sizeof(buf)); printf("*** %s\n", buf); } return (0); } int main() { RSA *rsa_priv; RSA *rsa_pub; unsigned char enc_bin[1024]; int enc_len; unsigned char dec_bin[1024]; int dec_len; char N[] = { "CB2DA098676495E3BEE8807573B658A3" }; char E[] = { "010001" }; char D[] = { "AE6BB41341A75AF849C19ADD86E4C751" }; char P[] = { "ECB6D81B9A287E2B" }; char Q[] = { "DBBB525D666C4B69" }; char DMP1[] = { "3381857C5C0ABB89" }; char DMQ1[] = { "C11B735B5A343A61" }; char IQMP[] = { "DECAD6D4EF77DE64" }; char msg[] = { "xyz" }; SSL_load_error_strings(); SSLeay_add_ssl_algorithms(); RAND_load_file("/dev/urandom", 1024); if ((rsa_priv = RSA_new()) == NULL) { goto err; } if ((rsa_pub = RSA_new()) == NULL) { goto err; } /* load public key */ printf("public key parameters:\n"); if (!BN_hex2bn(&rsa_pub->n, N)) { goto err; } printf(" N: %s\n", N); printf(" n: %s\n", BN_bn2hex(rsa_pub->n)); if (!BN_hex2bn(&rsa_pub->e, E)) { goto err; } printf(" E: %s\n", E); printf(" e: %s\n", BN_bn2hex(rsa_pub->e)); printf("public key size : %d bits\n", RSA_size(rsa_pub) * 8); /* load private key */ printf("private key parameters:\n"); if (!BN_hex2bn(&rsa_priv->n, N)) { goto err; } printf(" N: %s\n", N); printf(" n: %s\n", BN_bn2hex(rsa_priv->n)); if (!BN_hex2bn(&rsa_priv->d, D)) { goto err; } printf(" D: %s\n", D); printf(" d: %s\n", BN_bn2hex(rsa_priv->d)); if (!BN_hex2bn(&rsa_priv->e, E)) { goto err; } printf(" E: %s\n", E); printf(" e: %s\n", BN_bn2hex(rsa_priv->e)); printf("private key size: %d bits\n", RSA_size(rsa_priv) * 8); printf("clear data:\n"); print_hex(msg, strlen(msg)); /* encrypt */ if ((enc_len = RSA_private_encrypt(strlen(msg), msg, enc_bin, rsa_priv, RSA_PKCS1_PADDING)) < 0) { goto err; } printf("encrypted data:\n"); print_hex(enc_bin, enc_len); /* decrypt */ if ((dec_len = RSA_public_decrypt(enc_len, enc_bin, dec_bin, rsa_pub, RSA_PKCS1_PADDING)) < 0) { goto err; } printf("decrypted data:\n"); print_hex(dec_bin, dec_len); return (0); err: log_ssl(); return (1); }