• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PEM_read_RSAPrivateKey函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PEM_read_RSAPrivateKey函数的典型用法代码示例。如果您正苦于以下问题:C++ PEM_read_RSAPrivateKey函数的具体用法?C++ PEM_read_RSAPrivateKey怎么用?C++ PEM_read_RSAPrivateKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PEM_read_RSAPrivateKey函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: fopen

//-------------------------------------------------------------------------------------
bool KBE_RSA::loadPrivate(const std::string& keyname)
{
    FILE *fp = NULL;

	if(rsa_private == NULL)
	{
		fp = fopen(keyname.c_str(), "rb");
		if (!fp) {
			return false;
		}
		
		rsa_private = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL);
		if(NULL == rsa_private)
		{
			ERR_load_crypto_strings();
			char err[1024];
			char* errret = ERR_error_string(ERR_get_error(), err);
			ERROR_MSG(fmt::format("KBE_RSA::loadPrivate: PEM_read_RSAPrivateKey error({} : {})\n",
				errret, err));

			fclose(fp);
			return false;
		}
	}

	if(fp)
		fclose(fp);
	return rsa_private != NULL;
}
开发者ID:5432935,项目名称:kbengine,代码行数:30,代码来源:rsa.cpp


示例2: load_ca

/*
 * Load CA certificate and private key from current dir
 */
static int load_ca(char * ca_name, identity * ca)
{
    FILE * f ;
    RSA  * rsa ;
    char filename[FIELD_SZ+1] ;

    sprintf(filename, "%s.crt", ca_name);
    if ((f=fopen(filename, "r"))==NULL) {
        fprintf(stderr, "Cannot find: %s\n", filename);
        return -1 ; 
    }
    ca->cert = PEM_read_X509(f, NULL, NULL, NULL);
    fclose(f);

    sprintf(filename, "%s.key", ca_name);
    if ((f=fopen(filename, "r"))==NULL) {
        return -1 ; 
    }
    rsa = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL);
    fclose(f);

    ca->key = EVP_PKEY_new();
    EVP_PKEY_assign_RSA(ca->key, rsa);

    if (!X509_check_private_key(ca->cert, ca->key)) {
        fprintf(stderr, "CA certificate and private key do not match\n");
        return -1 ;
    }
    return 0;
}
开发者ID:randunel,项目名称:2cca,代码行数:33,代码来源:2cca.c


示例3: rsa_decrypt

//使用私钥解密
int rsa_decrypt(char *in, const char *key_path, char* out)
{
    RSA *p_rsa;
    FILE *file;
    int rsa_len;
    if ((file=fopen(key_path, "r"))==NULL)
    {
        perror("open key file error");
        return 0;
    }

    if ((p_rsa=PEM_read_RSAPrivateKey(file, NULL, NULL, NULL))==NULL)
    {
        ERR_print_errors_fp(stdout);
        return 0;
    }

    rsa_len=RSA_size(p_rsa);
    if (RSA_private_decrypt(rsa_len, (unsigned char*)in, (unsigned char*)out, p_rsa, RSA_NO_PADDING)<0)
    {
        return 0;
    }
    RSA_free(p_rsa);
    fclose(file);
    return 1;
}
开发者ID:AlexShiLucky,项目名称:demo,代码行数:27,代码来源:openssl_rsa_demo3.cpp


示例4: svObject

svRSAKey::svRSAKey(const string &pem)
	: svObject("svRSAKey"), type(svRSA_TYPE_NULL), key(NULL), mtime(0)
{
	struct stat key_stat;
	if (stat(pem.c_str(), &key_stat) == -1)
		throw svExRSAKeyStat(pem, strerror(errno));
	mtime = key_stat.st_mtime;

	FILE *h_key = fopen(pem.c_str(), "r");
	if (!h_key) throw svExRSAKeyOpen(pem, strerror(errno));

	if ((key = PEM_read_RSA_PUBKEY(h_key, NULL, NULL, NULL)))
		type = svRSA_TYPE_PUBLIC;
	else {
		rewind(h_key);

		if ((key = PEM_read_RSAPrivateKey(h_key, NULL, NULL, NULL)))
			type = svRSA_TYPE_PRIVATE;
		else {
			ERR_load_crypto_strings();
			svError("%s: %s: %s", name.c_str(), pem.c_str(),
				ERR_error_string(ERR_get_error(), NULL));
		}
	}

	fclose(h_key);

	if (type == svRSA_TYPE_NULL) throw svExRSAKeyInvalid(pem);
	name = pem;
}
开发者ID:adzymaniac,项目名称:dingap,代码行数:30,代码来源:svcrypto.cpp


示例5: fopen

Key::Key(string publicKeyFile, string privateKeyFile)
{
    rsa = NULL;
    privateKey = NULL;
    publicKey = NULL;
    priName = privateKeyFile;
    pubName = publicKeyFile;
    
    if (!privateKeyFile.empty()) {
        FILE *fp = fopen(privateKeyFile.c_str(), "r");
        if (fp == NULL) {
            cout << "Private Key File Error!" << endl;
            return ;
        }
        privateKey = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL);
        fclose(fp);
    }
    if (!publicKeyFile.empty()) {
        FILE *fp = fopen(publicKeyFile.c_str(), "r");
        if (fp == NULL) {
            cout << "Public Key File Error!" << endl;
            return ;
        }
//        rsa = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL);
        publicKey = PEM_read_RSAPublicKey(fp, NULL, NULL, NULL);
        fclose(fp);
        return ;
    }
    cout << "Error Open Private Key or Public Key!" << endl;
}
开发者ID:AnXi-TieGuanYin-Tea,项目名称:openssl-demo,代码行数:30,代码来源:Key.cpp


示例6: decrypt

char * decrypt(char * p_ecypt,int len_ecypt,char * priv_key){
    char * p_dcypt;
    int rsa_len;

    // open private key file
    FILE* priv_fp=fopen(priv_key,"r");
    if(priv_fp==NULL){
        printf("failed to open priv_key file %s!\n", priv_key);
        return NULL;
    }
    
    // read private key from private key file
    RSA *rsa2=PEM_read_RSAPrivateKey(priv_fp,NULL,NULL,NULL);
    if(rsa2==NULL){
        printf("unable to read private key!\n");
        return NULL;
    }
    
    rsa_len=RSA_size(rsa2);
    p_dcypt=(char *)malloc(rsa_len+1);
    memset(p_dcypt,0,rsa_len+1);
 
    // decrypt by using private key 
    decrylen=RSA_private_decrypt(len_ecypt,(const unsigned char*)p_ecypt,(unsigned char*)p_dcypt,rsa2,RSA_PKCS1_PADDING);
    if(decrylen==-1){
        printf("failed to decrypt!\n");
        return NULL;
    }
    
    fclose(priv_fp);
    return p_dcypt;
}
开发者ID:hellovictoria,项目名称:encrypt-Int-Class,代码行数:32,代码来源:safeopts1.cpp


示例7: sign

int
sign(char* private_key_path, unsigned char *msg, int msg_len,
     unsigned char *sig, unsigned int *sig_len)
{

    //Load private key
    FILE *fp = fopen(private_key_path, "r");
    if(!fp) {
        DEBUGMSG(ERROR, "Could not find private key\n");
        return 0;
    }
    RSA *rsa = (RSA *) PEM_read_RSAPrivateKey(fp,NULL,NULL,NULL);
    fclose(fp);
    if(!rsa) return 0;

    unsigned char md[SHA256_DIGEST_LENGTH];
    sha(msg, msg_len, md);

    //Compute signatur
    int err = RSA_sign(NID_sha256, md, SHA256_DIGEST_LENGTH, (unsigned char*)sig, (unsigned int*)sig_len, rsa);
    if(!err){
        printf("Error: %ul\n", (unsigned int)ERR_get_error());
    }
    RSA_free(rsa);
    return err;
}
开发者ID:cn-uofbasel,项目名称:ccn-lite,代码行数:26,代码来源:ccnl-crypto.c


示例8: my_decrypt

char* my_decrypt(char* str, char* path_key) {
	char* p_de;
	RSA* p_rsa;
	FILE *file;
	int rsa_len;
	if((file = fopen(path_key,"r")) == NULL) {
		perror("open key file error");
		return NULL;
	}

	if((p_rsa = PEM_read_RSAPrivateKey(file,NULL,NULL,NULL)) == NULL) {
		ERR_print_errors_fp(stdout);
		return NULL;
	}

	rsa_len = RSA_size(p_rsa);
	p_de = (unsigned char*)malloc(rsa_len + 1);
	memset(p_de,0,rsa_len+1);
	if(RSA_private_decrypt(rsa_len,(unsigned char*)str,(unsigned char*)p_de,p_rsa,RSA_NO_PADDING) < 0) {
		return NULL;
	}

	RSA_free(p_rsa);
	fclose(file);
	return p_de;
}
开发者ID:jerk1991,项目名称:FileServer,代码行数:26,代码来源:client.c


示例9: clearKey

int UtlCryptoKeyRsa::importFromFile(const char* pFilename)
{
   // Make sure we don't leave any previous keys hanging around
   clearKey();

   FILE *pFile = fopen(pFilename, "rt");
   if (!pFile)
      return -1;

   // First try to read a public key
   mpRsa = PEM_read_RSA_PUBKEY(pFile, 0, 0, 0);
   if (mpRsa)
      setKeyType(KEY_PUBLIC);
   else
   {
      // If that failed, try to read a private key
      fseek(pFile, 0, SEEK_SET);
      mpRsa = PEM_read_RSAPrivateKey(pFile, 0, 0, 0);
      if (mpRsa)
         setKeyType(KEY_PRIVATE);
   }

   fclose(pFile);

   if (isValid())
      return setLastError(0);
   else
      return -1;
}
开发者ID:John-Chan,项目名称:sipXtapi,代码行数:29,代码来源:UtlCryptoKeyRsa.cpp


示例10: rsa_encrypt_public

/*
 * rsa public key encrypt
 */
char* rsa_encrypt_public(unsigned char*txt,int txt_len,char* public_key_str,int p_len,int* enc_len)
{
	//char *public_key = "-----BEGIN RSA PUBLIC KEY-----\nMIGJAoGBAL331YpDOljAJznk4eNt0TfZJREYypIhWTN/gx0g1iUIaLPlFR7ydjaB\npd9V7G3GvvOf3mGijP+9LjKdgQ8p1pgDW7DeXZk2dTAeQ4hdY287/sw6NFKJxMXA\nFGoUdARObVespCZBdHSqo8kFMAjVGge6ZoH6nAjGzvIfijgsj+2jAgMBAAE=\n-----END RSA PUBLIC KEY-----\n";
	//char * private_key = "-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAKBgQC999WKQzpYwCc55OHjbdE32SURGMqSIVkzf4MdINYlCGiz5RUe\n8nY2gaXfVextxr7zn95hooz/vS4ynYEPKdaYA1uw3l2ZNnUwHkOIXWNvO/7MOjRS\nicTFwBRqFHQETm1XrKQmQXR0qqPJBTAI1RoHumaB+pwIxs7yH4o4LI/towIDAQAB\nAoGBAI1ALF2EI2w+ZGxdzcBntXtLUI5n2qfReBwcogcUlWYv3Hp2yb+bFV7uA8IO\nh6AQeYd4xcffL+wwZJtqFb6Ko25XAei8Os3xjb9k5fCcyrmyY+5oeXdQHlcbd/f8\niy8/rOEHZTr4iBXe/8ADlQZlRUkYCblPZ4i4BgzBUB6HzhxhAkEA8wJRx/FjOo6F\noO1aTewbvFIv4Dckqq5j/pBu9fkv1AhMxSfdGnsYcuIn15Y1/RlnpxrmJNWgryvd\n+6LJGDgjWQJBAMgfoINe80YiPCdMoboMd/u1uf1BhwujbiJPSrS40lc3jfyPmHA4\n8hppo8QuELI4rXRE/im4c+zmyphxEyULpVsCQQDnD96JGin65MeE1AsYqpdYwmEJ\ndgVkUXt88wK+2ZizqMyubpAa/M6rdgTiRc7CASUAzF/myEYIKdLh0NAbOk3JAkAE\nxEQVfPh8bipSoU+k19EvzKdOcfYef9kKtirIXTKdYzRdlKoD2kdh+6wr6xD4vcLb\n5xzKr5sLRIAE24SiOEHLAkB1TBlvvvIltttSc9lOpq3UhmtHQJaS32lD2Lk2/zNx\nW6Jbsk+sCQXM0ww4GTCpHMISfokEPtqOPikPcVFs98Oj\n-----END RSA PRIVATE KEY-----\n";
    RSA* rsa;
    int rsa_len;
    char *p_en;
    #if 1
    //public_key = rsa_key_seliaze(public_key_str);
    BIO* p_bio = BIO_new_mem_buf(public_key_str, -1);
    printf("rsa_encrypt is %p \n",p_bio);
    rsa = PEM_read_bio_RSAPublicKey(p_bio, NULL, NULL, NULL); //PEM_read_bio_RSAPrivateKey
    if ( rsa == NULL ) {
        printf("RSA is NULL\n");
        return NULL;
    }
    #else
    FILE* file=fopen("/tmp/r_pub.key","r");
    rsa=PEM_read_RSAPrivateKey(file,NULL,NULL,NULL);//PEM_read_RSAPrivateKey
    #endif
    rsa_len=RSA_size(rsa);
    p_en=(unsigned char *)calloc(rsa_len+1,1);
    printf("rsa length = %d\n",rsa_len);
    int rc=0;
    if((rc=RSA_public_encrypt(txt_len,(unsigned char *)txt,(unsigned char*)p_en,rsa,RSA_PKCS1_PADDING))<=0) {
        int e=ERR_get_error();
        printf("error code is:%s\n",ERR_error_string(e,NULL));
        return NULL;
    }
    printf("rsa length = %d\n",strlen(p_en));
    RSA_free(rsa);
    *enc_len = rc;
    return p_en;
}
开发者ID:whlzdy,项目名称:rastyle,代码行数:37,代码来源:acs_rsa.c


示例11: get_privkey_from_file

void get_privkey_from_file(Octstr* s, RSA** priv_key, Octstr* passwd)
{
		char *password;
		char *filename;
		
        /* Check errors!!!! */
        FILE* fp;

		filename = octstr_get_cstr(s);
		password = passwd != NULL ? octstr_get_cstr(passwd) : NULL;
        
		/* Open the file specified by "s" */
        fp = fopen(filename,"r");
        if (fp == NULL) warning(0,"Can't read private key %s", filename);
        
        /* Load up that there certificate */
        *priv_key = PEM_read_RSAPrivateKey(fp,NULL,NULL,password);

        /* Close the file specified by "s" */        
        fclose(fp);
        
        if (priv_key == NULL) { 
                ERR_print_errors_fp (stderr);
        }
}
开发者ID:LeeVidor,项目名称:kannel-mongodb,代码行数:25,代码来源:pki.c


示例12: wi_socket_context_set_ssl_privkey

wi_boolean_t wi_socket_context_set_ssl_privkey(wi_socket_context_t *context, wi_string_t *path) {
#ifdef WI_SSL
	FILE		*fp;
	
	fp = fopen(wi_string_cstring(path), "r");
	
	if(!fp) {
		wi_error_set_errno(errno);
		
		return false;
	}
		
	context->priv_rsa = PEM_read_RSAPrivateKey(fp, NULL, 0, NULL);
	
	if(!context->priv_rsa)
		wi_error_set_ssl_error();
	
	fclose(fp);
	
	return (context->priv_rsa != NULL);
#else
	wi_error_set_lib_error(WI_ERROR_SOCKET_NOSSL);
	
	return false;
#endif
}
开发者ID:ProfDrLuigi,项目名称:zanka,代码行数:26,代码来源:wi-socket.c


示例13: load_rsa_privkey

static RSA *
load_rsa_privkey(const char *path)
{
	FILE *fp;
	RSA *rsa = NULL;
	const char *p;
	char *passphrase = NULL;

	if ((fp = fopen(path, "r")) == 0)
		return NULL;

	if ((rsa = RSA_new()) == NULL) {
		fclose(fp);
		return NULL;
	}

	p = getenv("XBPS_PASSPHRASE");
	if (p) {
		passphrase = strdup(p);
	}
	rsa = PEM_read_RSAPrivateKey(fp, 0, NULL, passphrase);
	if (passphrase) {
		free(passphrase);
		passphrase = NULL;
	}
	fclose(fp);
	return rsa;
}
开发者ID:chneukirchen,项目名称:xbps,代码行数:28,代码来源:sign.c


示例14: rsa_encrypt_private

/*
 * rsa private encrypt
*/
char* rsa_encrypt_private(unsigned char*txt,int txt_len,char* public_key_str,int p_len,int* enc_len)
{
    RSA* rsa;
    int rsa_len;
    char *p_en;
    #if 1
    //public_key = rsa_key_seliaze(public_key_str);
    BIO* p_bio = BIO_new_mem_buf(public_key_str, -1);
    printf("rsa_encrypt is %p \n",p_bio);
    rsa = PEM_read_bio_RSAPrivateKey(p_bio, NULL, NULL, NULL); //PEM_read_bio_RSAPrivateKey
    if ( rsa == NULL ) {
        printf("RSA is NULL\n");
        return NULL;
    }
    #else
    FILE* file=fopen("/tmp/r_pub.key","r");
    rsa=PEM_read_RSAPrivateKey(file,NULL,NULL,NULL);//PEM_read_RSAPrivateKey
    #endif
    rsa_len=RSA_size(rsa);
    p_en=(unsigned char *)calloc(rsa_len+1,1);
    //printf("rsa length = %d\n",rsa_len);
    int rc=0;
    if((rc=RSA_private_encrypt(txt_len,(unsigned char *)txt,(unsigned char*)p_en,rsa,RSA_PKCS1_PADDING))<=0) {
        int e=ERR_get_error();
        printf("error code is:%s\n",ERR_error_string(e,NULL));
        return NULL;
    }
    RSA_free(rsa);
    *enc_len = rc;
    return p_en;
}
开发者ID:whlzdy,项目名称:rastyle,代码行数:34,代码来源:acs_rsa.c


示例15: wi_rsa_init_with_pem_file

wi_rsa_t * wi_rsa_init_with_pem_file(wi_rsa_t *rsa, wi_string_t *path) {
	FILE		*fp;
	
	fp = fopen(wi_string_cstring(path), "r");
	
	if(!fp) {
		wi_error_set_errno(errno);
		
		wi_release(rsa);
		
		return NULL;
	}
	
	rsa->rsa = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL);
	
	fclose(fp);
	
	if(!rsa->rsa) {
		wi_error_set_openssl_error();
		
		wi_release(rsa);
		
		return NULL;
	}
	
	return rsa;
}
开发者ID:ProfDrLuigi,项目名称:zanka,代码行数:27,代码来源:wi-crypto.c


示例16: openssl_read_pem_seckey

int
openssl_read_pem_seckey(const char *f, __ops_key_t *key, const char *type, int verbose)
{
	FILE	*fp;
	DSA	*dsa;
	RSA	*rsa;
	int	 ok;

	OpenSSL_add_all_algorithms();
	if ((fp = fopen(f, "r")) == NULL) {
		if (verbose) {
			(void) fprintf(stderr, "can't open '%s'\n", f);
		}
		return 0;
	}
	ok = 1;
	if (strcmp(type, "ssh-rsa") == 0) {
        rsa = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL);
        
        key->key.seckey.key.rsa.d = rsa->d;
		key->key.seckey.key.rsa.p = rsa->p;
		key->key.seckey.key.rsa.q = rsa->q;
		key->key.seckey.key.rsa.d = rsa->d;
	} else if (strcmp(type, "ssh-dss") == 0) {
		if ((dsa = PEM_read_DSAPrivateKey(fp, NULL, NULL, NULL)) == NULL) {
			ok = 0;
		} else {
			key->key.seckey.key.dsa.x = dsa->priv_key;
		}
	} else {
		ok = 0;
	}
	(void) fclose(fp);
	return ok;
}
开发者ID:Mynigma,项目名称:MCryptoLib,代码行数:35,代码来源:openssl_crypto.c


示例17: rsa_priv_decrypt

    int rsa_priv_decrypt(char ** str_out, char *str_in, size_t str_in_sz, char *key_file, char * keypass)
    {
        RSA * priv_key = NULL;
        FILE * priv_key_file;
        
        OpenSSL_add_all_algorithms();
        OpenSSL_add_all_ciphers();
        ERR_load_crypto_strings();
        
        priv_key_file = fopen(key_file, "rb");
        priv_key = PEM_read_RSAPrivateKey(priv_key_file, NULL, NULL, keypass);
        fclose(priv_key_file);

        if (!priv_key) {
            std::cerr << ERR_error_string(ERR_get_error(), NULL) << std::endl;
            return -1;
        }

        int key_size = RSA_size(priv_key);
        unsigned char *ustr_out = (unsigned char *)malloc(key_size);
        
        int len = RSA_private_decrypt(str_in_sz, (unsigned char *)&str_in[0], ustr_out, priv_key, RSA_PKCS1_PADDING);
        
        if (len == -1) {
            std::cerr << "RSA_private_decrypt error (rsa_priv_decrypt)." << std::endl;
            std::cerr << ERR_error_string(ERR_get_error(), NULL) << std::endl;
            return -1;
        }
        
        *str_out = (char *)ustr_out;
        return len;
    }
开发者ID:GameAP,项目名称:GDaemon2,代码行数:32,代码来源:gcrypt.cpp


示例18: lua_rsa_privkey_load

static gint
lua_rsa_privkey_load (lua_State *L)
{
	RSA *rsa = NULL, **prsa;
	const gchar *filename;
	FILE *f;

	filename = luaL_checkstring (L, 1);
	if (filename != NULL) {
		f = fopen (filename, "r");
		if (f == NULL) {
			msg_err ("cannot open private key from file: %s, %s",
				filename,
				strerror (errno));
			lua_pushnil (L);
		}
		else {
			if (!PEM_read_RSAPrivateKey (f, &rsa, NULL, NULL)) {
				msg_err ("cannot open private key from file: %s, %s", filename,
					ERR_error_string (ERR_get_error (), NULL));
				lua_pushnil (L);
			}
			else {
				prsa = lua_newuserdata (L, sizeof (RSA *));
				rspamd_lua_setclass (L, "rspamd{rsa_privkey}", -1);
				*prsa = rsa;
			}
			fclose (f);
		}
	}
	else {
		lua_pushnil (L);
	}
	return 1;
}
开发者ID:bryongloden,项目名称:rspamd,代码行数:35,代码来源:lua_rsa.c


示例19: rsa_get_priv_key

/**
 * rsa_get_priv_key() - read a private key from a .key file
 *
 * @keydir:	Directory containins the key
 * @name	Name of key file (will have a .key extension)
 * @rsap	Returns RSA object, or NULL on failure
 * @return 0 if ok, -ve on error (in which case *rsap will be set to NULL)
 */
static int rsa_get_priv_key(const char *keydir, const char *name, RSA **rsap)
{
	char path[1024];
	RSA *rsa;
	FILE *f;

	*rsap = NULL;
	snprintf(path, sizeof(path), "%s/%s.key", keydir, name);
	f = fopen(path, "r");
	if (!f) {
		fprintf(stderr, "Couldn't open RSA private key: '%s': %s\n",
			path, strerror(errno));
		return -ENOENT;
	}

	rsa = PEM_read_RSAPrivateKey(f, 0, NULL, path);
	if (!rsa) {
		rsa_err("Failure reading private key");
		fclose(f);
		return -EPROTO;
	}
	fclose(f);
	*rsap = rsa;

	return 0;
}
开发者ID:ahedlund,项目名称:u-boot-xlnx,代码行数:34,代码来源:rsa-sign.c


示例20: main

int
main(int argc, char **argv)
{
	FILE *kfile;
	RSA *rsa = NULL;
	char ndata[257], ddata[257];
	/* respond privatefile challenge */
	if (argc < 3)
	{
		puts("Usage: respond privatefile challenge [passphrase]");
		return 0;
	}

	if (argc == 4)
	{
		/* This is TOTALLY insecure and not recommended, but for
		** interfacing with irc client scripts, it's either this
		** or don't use a passphrase.
		**
		** The likelihood of a passphrase leaking isn't TOO great,
		** only ps auxww will show it, and even then, only at the
		** precise moment this is called.
		*/
		insecure_mode = 1;
		pass_param = argv[3];
	}

	if (!(kfile = fopen(argv[1], "r")))
	{
		puts("Could not open the private keyfile.");
		return 0;
	}
	
	SSLeay_add_all_ciphers();
	rsa = PEM_read_RSAPrivateKey(kfile, NULL,pass_cb, NULL);
  
	if(!rsa)
	{
		puts("Unable to read your private key, is the passphrase wrong?");
		return 0;
	}

	 fclose(kfile);
	if (hex_to_binary(argv[2], ndata, 128) != 128)
	{
		puts("Bad challenge.");
		return -1;
	}

	if (RSA_private_decrypt(128, (unsigned char*)ndata,
		(unsigned char*)ddata, rsa, RSA_PKCS1_PADDING) == -1)
	{
		puts("Decryption error.");
		return -1;
	}
	binary_to_hex((unsigned char*)ddata, ndata, 32);
	puts(ndata);
	return 0;
}
开发者ID:BackupTheBerlios,项目名称:shadowircd,代码行数:59,代码来源:respond.c



注:本文中的PEM_read_RSAPrivateKey函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PEM_read_X509函数代码示例发布时间:2022-05-30
下一篇:
C++ PEM_def_callback函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap