First public contribution.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Generate an RSA key.
27 #include <openssl/crypto.h>
28 #include <openssl/rand.h>
29 #include <openssl/rsa.h>
30 #include <openssl/bn.h>
39 static void printRSAKey(RSA* key)
41 printf("static RSA* createRSAKey()\n");
44 printCBN("n_data", key->n);
45 printCBN("e_data", key->e);
46 printCBN("d_data", key->d);
48 printf("\tRSA* key = RSA_new();\n");
49 printf("\tkey->n = BN_new();\n");
50 printf("\tkey->e = BN_new();\n");
51 printf("\tkey->d = BN_new();\n");
53 printf("\tBN_bin2bn(n_data, n_data_len, key->n);\n");
54 printf("\tBN_bin2bn(e_data, e_data_len, key->e);\n");
55 printf("\tBN_bin2bn(d_data, d_data_len, key->d);\n");
57 printf("\treturn key;\n");
62 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
64 static void badUsage()
66 printf("usage: gen_rsakey\n");
70 int main(int argc, char **argv)
73 int modulus_size = 1024;
79 RAND_seed(rnd_seed, sizeof rnd_seed);
81 rsa = RSA_generate_key(modulus_size, exponent, NULL, NULL);