Hello,
> N:
> 008796FB4EAAB5FCC21619608ECB34D4BD82D062BF136A54E7E0BF6B2991C2F0F93A161930D650AF939C8282431D291D0E6E9F69A09AF091345D60439569C5CB5ECA566740B6A69FE4BBF2DB9CC03786AEDF8F9522EB7F6096A1B900140E6AA7AF55198B87E68A69546631E9EF90666984123F5364BE2EA6E067BBAA8831A34B15
>
> E:
> 0040000081
After modifying sample program "decryption" with your public key
seems to work good.
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_pub;
unsigned char enc_bin[1024];
int enc_len;
unsigned char dec_bin[1024];
int dec_len;
char N[] = { "008796FB4EAAB5FCC21619608ECB34D4BD82D062BF136A54E7E0BF6B2991C2F0F93A161930D650AF939C8282431D291D0E6E9F69A09AF091345D60439569C5CB5ECA566740B6A69FE4BBF2DB9CC03786AEDF8F9522EB7F6096A1B900140E6AA7AF55198B87E68A69546631E9EF90666984123F5364BE2EA6E067BBAA8831A34B15" };
char E[] = { "0040000081" };
char msg[] = { "xyz" };
SSL_load_error_strings();
SSLeay_add_ssl_algorithms();
RAND_load_file("/dev/urandom", 1024);
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);
/* prepare "encrypted" data */
enc_len = RSA_size(rsa_pub);
memset(enc_bin, 1, enc_len);
/* decrypt */
if ((dec_len = RSA_public_decrypt(enc_len, enc_bin, dec_bin, rsa_pub,
RSA_NO_PADDING)) < 0) {
goto err;
}
printf("decrypted data:\n");
print_hex(dec_bin, dec_len);
return (0);
err:
log_ssl();
return (1);
}