本文整理汇总了C++中RSA_generate_key函数的典型用法代码示例。如果您正苦于以下问题:C++ RSA_generate_key函数的具体用法?C++ RSA_generate_key怎么用?C++ RSA_generate_key使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RSA_generate_key函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: testRSAGen
void testRSAGen(){
RSA *r;
int bits=512,ret;
unsigned long e=RSA_3;
BIGNUM *bne;
r=RSA_generate_key(bits,e,NULL,NULL);
RSA_print_fp(stdout,r,11);
JCG("--------------------------------\n");
RSA_free(r);
bne=BN_new();
ret=BN_set_word(bne,e);
r=RSA_new();
ret=RSA_generate_key_ex(r,bits,bne,NULL);
if(ret!=1)
{
JCG("RSA_generate_key_ex err!\n");
return;
}
/*RSA_print_fp(stdout,r,11); */
RSA_free(r);
}
开发者ID:princeofdream,项目名称:debug_src_full,代码行数:21,代码来源:sn_writer.cpp
示例2: main
int main(int argc, char *argv[])
{
RSA *key;
FILE *fp;
int keylen = 0;
if (argc != 2) {
fprintf(stderr, "Error: too many/few arguments.\nUsage: %s <numbits>\n", argv[0]);
return 1;
}
keylen = atoi(argv[1]);
if ((key = RSA_generate_key(keylen, 3, NULL, NULL)) == NULL) {
fprintf(stderr, "%s\n", ERR_error_string(ERR_get_error(), NULL));
return 1;
}
if (RSA_check_key(key) < 1)
{
fprintf(stderr, "Error: Problems while generating RSA Key.\nRetry.\n");
return 1;
}
fp = fopen(SECFILE,"w");
if (PEM_write_RSAPrivateKey(fp, key, NULL, NULL, 0, 0, NULL) == 0)
{
fprintf(stderr, "Error: problems while writing RSA Private Key.\n");
return 1;
}
fclose(fp);
fp = fopen(PUBFILE, "w");
if (PEM_write_RSAPublicKey(fp, key) == 0) {
fprintf(stderr, "Error: problems while writing RSA Public Key.\n");
return 1;
}
fclose(fp);
RSA_free(key);
printf("RSA key generated.\nLenght (bits) = %d\n", keylen);
return 0;
}
开发者ID:ia,项目名称:-junk,代码行数:40,代码来源:rsa-keygen.c
示例3: generateKeysRSA
int generateKeysRSA(EVP_PKEY** privKey, EVP_PKEY** pubKey){
RSA* rsa = NULL;
if(privKey == NULL || pubKey == NULL)
return 0;
*privKey = EVP_PKEY_new();
if(*privKey == NULL){
printf("ERR EVP_PKEY_new\n");
return 0;
}
*pubKey = EVP_PKEY_new();
if(*pubKey == NULL){
printf("ERR EVP_PKEY_new\n");
return 0;
}
rsa = RSA_generate_key(2048, RSA_F4, NULL, NULL);
if(rsa == NULL){
printf("ERR RSA_generate_key\n");
return 0;
}
if(1 != EVP_PKEY_assign_RSA(*privKey,
RSAPrivateKey_dup(rsa))){
printf("ERR EVP_PKEY_assign_RSA\n");
return 0;
}
if(1 != EVP_PKEY_assign_RSA(*pubKey,
RSAPublicKey_dup(rsa))){
printf("ERR EVP_PKEY_assign_RSA\n");
return 0;
}
return 1;
}
开发者ID:made1993,项目名称:chatlibgroupsig,代码行数:39,代码来源:funcionesRSA.c
示例4: GenerateRsaKey
BOOL GenerateRsaKey(INT32 nBit, RSA *pstPublicKey, RSA *pstPrivateKey)
{
RSA* pstRsa = RSA_generate_key(nBit, 65537, NULL, NULL);
if(NULL == pstRsa)
return false;
//Copy Public Key
pstPublicKey->n = NewBigNum();
CopyBigNum(pstPublicKey->n, pstRsa->n);
pstPublicKey->e = NewBigNum();
CopyBigNum(pstPublicKey->e, pstRsa->e);
pstPublicKey->d = NULL;
pstPublicKey->p = NULL;
pstPublicKey->q = NULL;
pstPublicKey->dmp1 = NewBigNum();
CopyBigNum(pstPublicKey->dmp1, pstRsa->dmp1);
pstPublicKey->dmq1 = NewBigNum();
CopyBigNum(pstPublicKey->dmq1, pstRsa->dmq1);
//Copy Private Key
pstPrivateKey->n = NewBigNum();
CopyBigNum(pstPrivateKey->n, pstRsa->n);
pstPrivateKey->e = NewBigNum();
CopyBigNum(pstPrivateKey->e, pstRsa->e);
pstPrivateKey->d = NewBigNum();
CopyBigNum(pstPrivateKey->d, pstRsa->d);
pstPrivateKey->p = NewBigNum();
CopyBigNum(pstPrivateKey->p, pstRsa->p);
pstPrivateKey->q = NewBigNum();
CopyBigNum(pstPrivateKey->q, pstRsa->q);
pstPrivateKey->dmp1 = NewBigNum();
CopyBigNum(pstPrivateKey->dmp1, pstRsa->dmp1);
pstPrivateKey->dmq1 = NewBigNum();
CopyBigNum(pstPrivateKey->dmq1, pstRsa->dmq1);
RSA_free(pstRsa);
return true;
}
开发者ID:mildrock,项目名称:dummy,代码行数:39,代码来源:sdrsahlp.cpp
示例5:
/*
* genrsa: generates a new rsa key pair and returns the private key in the RSA
* format. If `pub' is not null, it stores in it the pointer to a newly
* allocated dump of the public key that is `*pub_len' bytes. The same is for
* `priv' and `priv_len'.
* On error null is returned.
*/
RSA *genrsa(int key_bits, u_char **pub, u_int *pub_len, u_char **priv, u_int *priv_len)
{
RSA *rsa=0;
int len;
rsa=RSA_generate_key(key_bits, RSA_F4, NULL, NULL);
if (!rsa) {
debug(DBG_SOFT, "RSA key generation failed");
goto error;
}
if(priv) {
*priv=0;
len=i2d_RSAPrivateKey(rsa, priv);
if(priv_len)
*priv_len=len;
if(len <= 0) {
debug(DBG_SOFT, "Cannot dump RSA public key: %s", ssl_strerr());
goto error;
}
}
if(pub) {
*pub=0;
len=i2d_RSAPublicKey(rsa, pub);
if(pub_len)
*pub_len=len;
if(len <= 0) {
debug(DBG_SOFT, "Cannot dump RSA public key: %s", ssl_strerr());
goto error;
}
}
return rsa;
error:
if(rsa)
RSA_free(rsa);
return 0;
}
开发者ID:StrangeTcy,项目名称:netsukuku,代码行数:46,代码来源:crypto.c
示例6: generate_key
int
generate_key(int length, PyObject **py_private_key_ndn,
PyObject **py_public_key_ndn, PyObject **py_public_key_digest,
int *public_key_digest_len)
{
RSA *private_key_rsa;
struct ndn_pkey *private_key = NULL;
int r;
seed_prng();
private_key_rsa = RSA_generate_key(length, 65537, NULL, NULL);
private_key = (struct ndn_pkey *)EVP_PKEY_new();
EVP_PKEY_assign_RSA ((EVP_PKEY *)private_key, private_key_rsa);
save_seed ();
if (!private_key_rsa || !private_key) {
unsigned int err;
err = ERR_get_error();
PyErr_Format(g_PyExc_NDNKeyError, "Unable to generate the"
" key: %s", ERR_reason_error_string(err));
return -1;
}
r = ndn_keypair(0, private_key, py_private_key_ndn,
py_public_key_ndn);
if (r < 0)
return -1;
r = create_public_key_digest(private_key, py_public_key_digest,
public_key_digest_len);
if (r < 0)
return -1;
EVP_PKEY_free ((EVP_PKEY*)private_key);
return 0;
}
开发者ID:cawka,项目名称:PyNDN,代码行数:38,代码来源:key_utils.c
示例7: malloc
struct login_ctx *login_create(char *username, char *password) {
struct login_ctx *l;
l = malloc(sizeof(struct login_ctx));
if(l == NULL)
return NULL;
l->state = 0;
l->error = SP_LOGIN_ERROR_OK;
l->sock = -1;
l->service_records = NULL;
l->server_ai = NULL;
l->client_parameters = NULL;
l->server_parameters = NULL;
/* Client key pair */
l->rsa = RSA_generate_key(1024, 65537, NULL, NULL);
/* Diffie-Hellman parameters */
l->dh = DH_new ();
l->dh->p = BN_bin2bn(DH_prime, 96, NULL);
l->dh->g = BN_bin2bn(DH_generator, 1, NULL);
DH_generate_key(l->dh);
strncpy(l->username, username, sizeof(l->username) - 1);
l->username[sizeof(l->username) - 1] = 0;
strncpy(l->password, password, sizeof(l->password) - 1);
l->password[sizeof(l->password) - 1] = 0;
DSFYDEBUG("Login context created at %p\n", l);
return l;
}
开发者ID:Kitof,项目名称:openspotify,代码行数:38,代码来源:login.c
示例8: kaa_generate_pub_key
static void kaa_generate_pub_key(void)
{
const int kBits = 2048;
const int kExp = 65537;
RSA *rsa = RSA_generate_key(kBits, kExp, 0, 0);
BIO *bio_pem = BIO_new(BIO_s_mem());
i2d_RSA_PUBKEY_bio(bio_pem, rsa);
kaa_public_key_length = BIO_pending(bio_pem);
kaa_public_key = (char *) KAA_MALLOC(kaa_public_key_length);
if (!kaa_public_key) {
kaa_public_key_length = 0;
BIO_free_all(bio_pem);
RSA_free(rsa);
return;
}
BIO_read(bio_pem, kaa_public_key, kaa_public_key_length);
BIO_free_all(bio_pem);
RSA_free(rsa);
}
开发者ID:BillTheBest,项目名称:kaa,代码行数:23,代码来源:posix_key_utils.c
示例9: sample_job_outputs_stuff
// A job that does work, with output we care about (pub/priv key)
void sample_job_outputs_stuff(lsq_job_args *args)
{
unsigned char * output = (unsigned char *) args->output_buffer.memory;
int encoded_len = 0;
RSA * rsa_key = RSA_generate_key(2048, 65537, NULL, NULL);
memset(args->output_buffer.memory, 0, args->output_buffer.size);
if(rsa_key)
{
// Make sure it'll fit...
encoded_len = i2d_RSAPublicKey(rsa_key, NULL);
//encoded_len += i2d_RSAPrivateKey(rsa_key, NULL);
memcpy(output, &encoded_len, 4);
output += 4;
if(encoded_len <= args->output_buffer.size)
{
i2d_RSAPublicKey(rsa_key, &output);
//i2d_RSAPrivateKey(rsa_key, &output);
}
}
}
开发者ID:nate-yocom,项目名称:libsuperqueue,代码行数:24,代码来源:test_app.c
示例10: MakeX509CSR
int MakeX509CSR(const char *cn, const char *keyfile, const char *csrfile)
{
InitializeOpenSSL();
RSA *rsa = RSA_generate_key(4096, RSA_F4, NULL, NULL);
BIO *bio = BIO_new(BIO_s_file());
BIO_write_filename(bio, const_cast<char *>(keyfile));
PEM_write_bio_RSAPrivateKey(bio, rsa, NULL, NULL, 0, NULL, NULL);
BIO_free(bio);
X509_REQ *req = X509_REQ_new();
if (!req)
return 0;
EVP_PKEY *key = EVP_PKEY_new();
EVP_PKEY_assign_RSA(key, rsa);
X509_REQ_set_version(req, 0);
X509_REQ_set_pubkey(req, key);
X509_NAME *name = X509_REQ_get_subject_name(req);
X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, (unsigned char *)cn, -1, -1, 0);
X509_REQ_sign(req, key, EVP_sha1());
EVP_PKEY_free(key);
bio = BIO_new(BIO_s_file());
BIO_write_filename(bio, const_cast<char *>(csrfile));
PEM_write_bio_X509_REQ(bio, req);
BIO_free(bio);
X509_REQ_free(req);
return 1;
}
开发者ID:carroarmato0,项目名称:icinga2,代码行数:37,代码来源:tlsutility.cpp
示例11: key_new
/*
* Create a new key
*/
int key_new(key_t *key)
{
RSA *rsa = NULL;
EVP_PKEY *k = NULL;
/* Create key pair container */
k = EVP_PKEY_new();
if (k == NULL) {
return 0;
}
/* Generate a new RSA key */
rsa = RSA_generate_key(RSA_KEY_BITS, RSA_F4, NULL, NULL);
if (EVP_PKEY_assign_RSA(k, rsa)) {
key->key = k;
return 1;
} else {
printf("Cannot assign RSA key\n");
}
if (k)
EVP_PKEY_free(k);
return 0;
}
开发者ID:ansonn,项目名称:arm-trusted-firmware,代码行数:27,代码来源:key.c
示例12: main
main(){
RSA *rsa;
int i,len,en_len;
unsigned char buf[2048],*p,*key_p;
rsa=RSA_generate_key(1024,RSA_F4,NULL,NULL);
p=buf;
len=i2d_RSAPublicKey(rsa,&p);
len+=i2d_RSAPrivateKey(rsa,&p);
RSA_free(rsa);
key_p = (unsigned char*)malloc(len);
memcpy(key_p,buf,len);
p = buf;
base64_encode(key_p,len,p,&en_len);
printf("%s\n",buf);
free(key_p);
}
开发者ID:noikiy,项目名称:shopexts,代码行数:24,代码来源:i2d.c
示例13: makersacert
void makersacert(int days, char* commonname, int bits)
{
RSA *key;
EVP_PKEY *pkey;
X509 *x;
FILE *out;
key = RSA_generate_key(bits, RSA_F4, NULL, NULL);
pkey = EVP_PKEY_new();
EVP_PKEY_set1_RSA(pkey, key);
x = makeselfcert(pkey, days, commonname, EVP_sha256());
out = fopen("rsa_cert.pem", "w");
if (out == NULL)
exit(-1);
PEM_write_X509(out, x);
fclose(out);
out = fopen("rsa_cert_key.pem", "w");
if (out == NULL)
exit(-1);
PEM_write_RSAPrivateKey(out, key, NULL, NULL, 0, NULL, NULL);
fclose(out);
}
开发者ID:reschly,项目名称:certgeneration,代码行数:24,代码来源:makersacert.c
示例14: FIPS_rsa_test
/* RSA: generate keys and encrypt and decrypt known plaintext, verify result
* matches the original plaintext
*/
static int FIPS_rsa_test()
{
RSA *key;
unsigned char input_ptext[] = "etaonrishdlc";
unsigned char ctext[256];
unsigned char ptext[256];
int n;
ERR_clear_error();
key = RSA_generate_key(1024,65537,NULL,NULL);
if (!key)
return 0;
n = RSA_size(key);
n = RSA_public_encrypt(sizeof(input_ptext) - 1,input_ptext,ctext,key,RSA_PKCS1_PADDING);
if (n < 0)
return 0;
n = RSA_private_decrypt(n,ctext,ptext,key,RSA_PKCS1_PADDING);
if (n < 0)
return 0;
RSA_free(key);
if (memcmp(input_ptext,ptext,sizeof(input_ptext) - 1))
return 0;
return 1;
}
开发者ID:aosm,项目名称:OpenSSL097,代码行数:27,代码来源:fips_test_suite.c
示例15: mprError
//.........这里部分代码省略.........
mprLog(4, "SSL: %s: Using ciphers %s\n", hostName, ciphers);
SSL_CTX_set_cipher_list(context, ciphers);
//
// Configure the client verification certificate locations
//
if (verifyClient) {
if (caFile == 0 && caPath == 0) {
mprError(MPR_L, MPR_LOG,
"OpenSSL: Must define CA certificates if using client verification");
SSL_CTX_free(context);
context = 0;
return MPR_ERR_BAD_STATE;
}
if (caFile || caPath) {
if ((!SSL_CTX_load_verify_locations(context, caFile, caPath)) ||
(!SSL_CTX_set_default_verify_paths(context))) {
mprError(MPR_L, MPR_LOG,
"OpenSSL: Unable to set certificate locations");
SSL_CTX_free(context);
context = 0;
return MPR_ERR_CANT_ACCESS;
}
if (caFile) {
STACK_OF(X509_NAME) *certNames;
certNames = SSL_load_client_CA_file(caFile);
if (certNames == 0) {
} else {
//
// Define the list of CA certificates to send to the client
// before they send their client certificate for validation
//
SSL_CTX_set_client_CA_list(context, certNames);
}
}
}
mprLog(4, "SSL: %s: is verifying client connections\n", hostName);
if (caFile) {
mprLog(4, "SSL: %s: Using certificates from %s\n", hostName,
caFile);
} else if (caPath) {
mprLog(4, "SSL: %s: Using certificates from directory %s\n",
hostName, caPath);
}
SSL_CTX_set_verify(context, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, verifyX509Certificate);
SSL_CTX_set_verify_depth(context, verifyDepth);
} else {
SSL_CTX_set_verify(context, SSL_VERIFY_NONE, verifyX509Certificate);
}
//
// Define callbacks
//
SSL_CTX_set_tmp_rsa_callback(context, rsaCallback);
SSL_CTX_set_tmp_dh_callback(context, dhCallback);
//
// Enable all buggy client work-arounds
//
SSL_CTX_set_options(context, SSL_OP_ALL);
#ifdef SSL_OP_NO_TICKET
SSL_CTX_set_options(context, SSL_OP_NO_TICKET);
#endif
#ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
SSL_CTX_set_options(context, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
#endif
SSL_CTX_set_mode(context, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_AUTO_RETRY);
//
// Select the required protocols
//
SSL_CTX_set_options(context, SSL_OP_NO_SSLv2);
if (!(protocols & MPR_HTTP_PROTO_SSLV3)) {
SSL_CTX_set_options(context, SSL_OP_NO_SSLv3);
mprLog(4, "SSL: %s: Disabling SSLv3\n", hostName);
}
if (!(protocols & MPR_HTTP_PROTO_TLSV1)) {
SSL_CTX_set_options(context, SSL_OP_NO_TLSv1);
mprLog(4, "SSL: %s: Disabling TLSv1\n", hostName);
}
//
// Ensure we generate a new private key for each connection
//
SSL_CTX_set_options(context, SSL_OP_SINGLE_DH_USE);
//
// Pre-generate some keys that are slow to compute
//
rsaKey512 = RSA_generate_key(512, RSA_F4, 0, 0);
rsaKey1024 = RSA_generate_key(1024, RSA_F4, 0, 0);
dhKey512 = get_dh512();
dhKey1024 = get_dh1024();
return 0;
}
开发者ID:embedthis,项目名称:appweb-2,代码行数:101,代码来源:openSslModule.cpp
示例16: __ops_keydata_free
/**
\ingroup HighLevel_KeyGenerate
\brief Generates an RSA keypair
\param numbits Modulus size
\param e Public Exponent
\param keydata Pointer to keydata struct to hold new key
\return 1 if key generated successfully; otherwise 0
\note It is the caller's responsibility to call __ops_keydata_free(keydata)
*/
static unsigned
rsa_generate_keypair(__ops_key_t *keydata,
const int numbits,
const unsigned long e,
const char *hashalg,
const char *cipher)
{
__ops_seckey_t *seckey;
RSA *rsa;
BN_CTX *ctx;
__ops_output_t *output;
__ops_memory_t *mem;
ctx = BN_CTX_new();
__ops_keydata_init(keydata, OPS_PTAG_CT_SECRET_KEY);
seckey = __ops_get_writable_seckey(keydata);
/* generate the key pair */
rsa = RSA_generate_key(numbits, e, NULL, NULL);
/* populate __ops key from ssl key */
seckey->pubkey.version = OPS_V4;
seckey->pubkey.birthtime = time(NULL);
seckey->pubkey.days_valid = 0;
seckey->pubkey.alg = OPS_PKA_RSA;
seckey->pubkey.key.rsa.n = BN_dup(rsa->n);
seckey->pubkey.key.rsa.e = BN_dup(rsa->e);
seckey->s2k_usage = OPS_S2KU_ENCRYPTED_AND_HASHED;
seckey->s2k_specifier = OPS_S2KS_SALTED;
/* seckey->s2k_specifier=OPS_S2KS_SIMPLE; */
if ((seckey->hash_alg = __ops_str_to_hash_alg(hashalg)) == OPS_HASH_UNKNOWN) {
seckey->hash_alg = OPS_HASH_SHA1;
}
seckey->alg = __ops_str_to_cipher(cipher);
seckey->octetc = 0;
seckey->checksum = 0;
seckey->key.rsa.d = BN_dup(rsa->d);
seckey->key.rsa.p = BN_dup(rsa->p);
seckey->key.rsa.q = BN_dup(rsa->q);
seckey->key.rsa.u = BN_mod_inverse(NULL, rsa->p, rsa->q, ctx);
if (seckey->key.rsa.u == NULL) {
(void) fprintf(stderr, "seckey->key.rsa.u is NULL\n");
return 0;
}
BN_CTX_free(ctx);
RSA_free(rsa);
__ops_keyid(keydata->sigid, OPS_KEY_ID_SIZE, &keydata->key.seckey.pubkey, seckey->hash_alg);
__ops_fingerprint(&keydata->sigfingerprint, &keydata->key.seckey.pubkey, seckey->hash_alg);
/* Generate checksum */
output = NULL;
mem = NULL;
__ops_setup_memory_write(&output, &mem, 128);
__ops_push_checksum_writer(output, seckey);
switch (seckey->pubkey.alg) {
case OPS_PKA_DSA:
return __ops_write_mpi(output, seckey->key.dsa.x);
case OPS_PKA_RSA:
case OPS_PKA_RSA_ENCRYPT_ONLY:
case OPS_PKA_RSA_SIGN_ONLY:
if (!__ops_write_mpi(output, seckey->key.rsa.d) ||
!__ops_write_mpi(output, seckey->key.rsa.p) ||
!__ops_write_mpi(output, seckey->key.rsa.q) ||
!__ops_write_mpi(output, seckey->key.rsa.u)) {
return 0;
}
break;
case OPS_PKA_ELGAMAL:
return __ops_write_mpi(output, seckey->key.elgamal.x);
default:
(void) fprintf(stderr, "Bad seckey->pubkey.alg\n");
return 0;
}
/* close rather than pop, since its the only one on the stack */
__ops_writer_close(output);
__ops_teardown_memory_write(output, mem);
/* should now have checksum in seckey struct */
//.........这里部分代码省略.........
开发者ID:Mynigma,项目名称:MCryptoLib,代码行数:101,代码来源:openssl_crypto.c
示例17: memcpy
SESSION *session_init_client (void)
{
SESSION *session;
if ((session = (SESSION *) calloc (1, sizeof (SESSION))) == NULL)
return NULL;
session->client_OS = 0x00; /* 0x00 == Windows, 0x01 == Mac OS X */
memcpy(session->client_id, "\x01\x04\x01\x01", 4);
session->client_revision = 99999;
/*
* Client and server generate 16 random bytes each.
*/
RAND_bytes (session->client_random_16, 16);
if ((session->rsa =
RSA_generate_key (1024, 65537, NULL, NULL)) == NULL) {
DSFYDEBUG ("RSA key generation failed with error %lu\n",
ERR_get_error ());
}
assert (session->rsa != NULL);
/*
* Create a private and public key.
* This, along with key signing, is used to securely
* agree on a session key for the Shannon stream cipher.
*
*/
session->dh = DH_new ();
session->dh->p = BN_bin2bn (DH_prime, 96, NULL);
session->dh->g = BN_bin2bn (DH_generator, 1, NULL);
assert (DH_generate_key (session->dh) == 1);
BN_bn2bin (session->dh->priv_key, session->my_priv_key);
BN_bn2bin (session->dh->pub_key, session->my_pub_key);
/*
* Found in Storage.dat (cache) at offset 16.
* Automatically generated, but we're lazy.
*
*/
memcpy (session->cache_hash,
"\xf4\xc2\xaa\x05\xe8\x25\xa7\xb5\xe4\xe6\x59\x0f\x3d\xd0\xbe\x0a\xef\x20\x51\x95",
20);
session->cache_hash[0] = (unsigned char) getpid ();
session->ap_sock = -1;
session->username[0] = 0;
session->server_host[0] = 0;
session->server_port = 0;
session->key_recv_IV = 0;
session->key_send_IV = 0;
session->user_info.username[0] = 0;
session->user_info.country[0] = 0;
session->user_info.server_host[0] = 0;
session->user_info.server_port = 0;
return session;
}
开发者ID:estock,项目名称:spot,代码行数:62,代码来源:session.c
示例18: keyGenerator
void keyGenerator(int fileIndex, int keyLength)
{
int err=0;
int size = 0;
char * buffer = 0;
char * buffer2 = 0;
FILE * publicKeyFile = NULL;
FILE * privateKeyFile = NULL;
char fileName[256];
char publicKeyFileName[512];
char privateKeyFileName[512];
for(int i = 0; i< 1000; i++)
{
if( i < 10)
{
sprintf(publicKeyFileName, "%d00%d-PublicKey", fileIndex, i);
sprintf(privateKeyFileName, "%d00%d-PrivateKey", fileIndex,i);
}
else if(i >= 10 && i < 100)
{
sprintf(publicKeyFileName, "%d0%d-PublicKey", fileIndex, i);
sprintf(privateKeyFileName, "%d0%d-PrivateKey", fileIndex,i);
}
else
{
sprintf(publicKeyFileName, "%d%d-PublicKey", fileIndex, i);
sprintf(privateKeyFileName, "%d%d-PrivateKey", fileIndex,i);
}
RSA * rsa;
rsa = RSA_generate_key(keyLength, RSA_F4, NULL, (char*)stdout);
int lenE = 0;
unsigned char * tmp = new unsigned char[keyLength];
unsigned char *p;
//public key
p = tmp;
lenE=i2d_RSAPublicKey(rsa,&p);
buffer = new char[lenE];
memcpy(buffer, tmp, lenE);
publicKeyFile = fopen(publicKeyFileName, "wb");
if (publicKeyFile == NULL)
perror("publicKey");
fwrite(buffer, sizeof(char), lenE, publicKeyFile);
fclose(publicKeyFile);
//private key
p = tmp;
int lenD=i2d_RSAPrivateKey(rsa,&p);
buffer2 = new char[lenD];
memcpy(buffer2, tmp, lenD);
privateKeyFile = fopen(privateKeyFileName, "wb");
if (privateKeyFile == NULL)
perror("PrivateKey");
fwrite(buffer2, sizeof(char), lenD, privateKeyFile);
fclose(privateKeyFile);
RSA_free(rsa);
delete [] buffer;
delete [] buffer2;
delete [] tmp;
}
}
开发者ID:jlautarosilva,项目名称:cluster,代码行数:69,代码来源:DistKeyGen.c
示例19: tmp_rsa_callback
RSA* tmp_rsa_callback( SSL* /*s*/, int is_export, int keylength )
{
return RSA_generate_key( keylength, RSA_F4, 0, 0 );
}
开发者ID:ForNeVeR,项目名称:cthulhu-bot,代码行数:4,代码来源:tlsopensslserver.cpp
示例20: westcos_pkcs15init_generate_key
/*
* Generate key
*/
static int westcos_pkcs15init_generate_key(sc_profile_t *profile,
sc_pkcs15_card_t *p15card,
sc_pkcs15_object_t *obj,
sc_pkcs15_pubkey_t *pubkey)
{
#ifndef ENABLE_OPENSSL
return SC_ERROR_NOT_SUPPORTED;
#else
int r = SC_ERROR_UNKNOWN;
long lg;
u8 *p;
sc_pkcs15_prkey_info_t *key_info = (sc_pkcs15_prkey_info_t *) obj->data;
RSA *rsa = NULL;
BIGNUM *bn = NULL;
BIO *mem = NULL;
sc_file_t *prkf = NULL;
if (obj->type != SC_PKCS15_TYPE_PRKEY_RSA) {
return SC_ERROR_NOT_SUPPORTED;
}
#if OPENSSL_VERSION_NUMBER>=0x00908000L
rsa = RSA_new();
bn = BN_new();
mem = BIO_new(BIO_s_mem());
if(rsa == NULL || bn == NULL || mem == NULL)
{
r = SC_ERROR_OUT_OF_MEMORY;
goto out;
}
if(!BN_set_word(bn, RSA_F4) ||
!RSA_generate_key_ex(rsa, key_info->modulus_length, bn, NULL))
#else
mem = BIO_new(BIO_s_mem());
if(mem == NULL)
{
r = SC_ERROR_OUT_OF_MEMORY;
goto out;
}
rsa = RSA_generate_key(key_info->modulus_length, RSA_F4, NULL, NULL);
if (!rsa)
#endif
{
r = SC_ERROR_UNKNOWN;
goto out;
}
rsa->meth = RSA_PKCS1_SSLeay();
if(pubkey != NULL)
{
if(!i2d_RSAPublicKey_bio(mem, rsa))
{
r = SC_ERROR_UNKNOWN;
goto out;
}
lg = BIO_get_mem_data(mem, &p);
pubkey->algorithm = SC_ALGORITHM_RSA;
r = sc_pkcs15_decode_pubkey(p15card->card->ctx, pubkey, p, lg);
}
(void) BIO_reset(mem);
if(!i2d_RSAPrivateKey_bio(mem, rsa))
{
r = SC_ERROR_UNKNOWN;
goto out;
}
lg = BIO_get_mem_data(mem, &p);
/* Get the private key file */
r = sc_profile_get_file_by_path(profile, &key_info->path, &prkf);
if (r < 0)
{
char pbuf[SC_MAX_PATH_STRING_SIZE];
r = sc_path_print(pbuf, sizeof(pbuf), &key_info->path);
if (r != SC_SUCCESS)
pbuf[0] = '\0';
goto out;
}
prkf->size = lg;
r = sc_pkcs15init_create_file(profile, p15card, prkf);
if(r) goto out;
//.........这里部分代码省略.........
开发者ID:exciler,项目名称:OpenSC,代码行数:101,代码来源:pkcs15-westcos.c
注:本文中的RSA_generate_key函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论