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

C++ RSA_public_encrypt函数代码示例

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

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



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

示例1: pkey_rsa_encrypt

static int pkey_rsa_encrypt(EVP_PKEY_CTX *ctx,
                            unsigned char *out, size_t *outlen,
                            const unsigned char *in, size_t inlen)
{
    int ret;
    RSA_PKEY_CTX *rctx = ctx->data;
    if (rctx->pad_mode == RSA_PKCS1_OAEP_PADDING) {
        int klen = RSA_size(ctx->pkey->pkey.rsa);
        if (!setup_tbuf(rctx, ctx))
            return -1;
        if (!RSA_padding_add_PKCS1_OAEP_mgf1(rctx->tbuf, klen,
                                             in, inlen,
                                             rctx->oaep_label,
                                             rctx->oaep_labellen,
                                             rctx->md, rctx->mgf1md))
            return -1;
        ret = RSA_public_encrypt(klen, rctx->tbuf, out,
                                 ctx->pkey->pkey.rsa, RSA_NO_PADDING);
    } else
        ret = RSA_public_encrypt(inlen, in, out, ctx->pkey->pkey.rsa,
                                 rctx->pad_mode);
    if (ret < 0)
        return ret;
    *outlen = ret;
    return 1;
}
开发者ID:5y,项目名称:node,代码行数:26,代码来源:rsa_pmeth.c


示例2: rsa_public_encrypt

void
rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA *key)
{
	u_char *inbuf, *outbuf;
	int len, ilen, olen;

	if (BN_num_bits(key->e) < 2 || !BN_is_odd(key->e))
		errx(1, "rsa_public_encrypt() exponent too small or not odd");

	olen = BN_num_bytes(key->n);
	outbuf = (u_char*)malloc(olen);

	ilen = BN_num_bytes(in);
	inbuf = (u_char*)malloc(ilen);

	if (outbuf == NULL || inbuf == NULL)
		err(1, "malloc");
	
	BN_bn2bin(in, inbuf);
	
	if ((len = RSA_public_encrypt(ilen, inbuf, outbuf, key,
				      RSA_PKCS1_PADDING)) <= 0)
		errx(1, "rsa_public_encrypt() failed");

	BN_bin2bn(outbuf, len, out);

	memset(outbuf, 0, olen);
	memset(inbuf, 0, ilen);
	free(outbuf);
	free(inbuf);
}
开发者ID:Lorindellia,项目名称:dsniff,代码行数:31,代码来源:sshcrypto.c


示例3: 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


示例4: rsa_encrypt

    array::array* rsa_encrypt(const array::array* data, RSA* rsa) {

        if(data == nullptr || data == 0) {
            std::cout << "(i) " << __func__ << ": empty or null data." << std::endl;
            return nullptr;
        }

        if(rsa == nullptr || rsa == 0) {
            std::cout << "(i)" << __func__ << ": empty or null key." << std::endl;
            return nullptr;
        }

        int result;
        byte* out = new byte[RSA_size(rsa)];

        result = RSA_public_encrypt(data->length, data->data, out, rsa, RSA_PKCS1_PADDING);

        if(result < 0) {
            delete[] out;
            return nullptr;
        }

        array::array* encrypted = array::create(result, out);
        delete[] out;

        return encrypted;
    }
开发者ID:skull0801,项目名称:EP1_OO,代码行数:27,代码来源:crypto.cpp


示例5: EVP_PKEY_encrypt_old

/* GMSSL: EVP_PKEY_encrypt_old() is modified */
int EVP_PKEY_encrypt_old(unsigned char *out, const unsigned char *in,
	int inlen, EVP_PKEY *pkey)
{
	int ret = 0;
	EVP_PKEY_CTX *ctx = NULL;
	size_t size;

	if (pkey->type == EVP_PKEY_RSA) {
		ret = RSA_public_encrypt(inlen, in, out, pkey->pkey.rsa,
			RSA_PKCS1_PADDING);
	} else {
		if (!(ctx = EVP_PKEY_CTX_new(pkey, NULL))) {
			return 0;
		}
		if (1 != EVP_PKEY_encrypt_init(ctx)) {
			return 0;
		}
		if (1 != EVP_PKEY_encrypt(ctx, out, &size, in, inlen)) {
			goto end;
		}
		ret = (int)size;
	}
end:
	EVP_PKEY_CTX_free(ctx);
	return ret;
}
开发者ID:BeyondChallenge,项目名称:GmSSL,代码行数:27,代码来源:p_enc.c


示例6: RSAEncrypt

/**
* 功能描述:RSA加密
* @param pData:原始数据
* @param ilen: 原始数据长度
* @param pEncodeData: 加密后数据
* @return -1: 失败, 其他: 加密数据长度
**/
int RSAEncrypt(const char* pData , int iLen, char** pEncodeData)
{
    char chPublicKey[] = "-----BEGIN PUBLIC KEY-----\n"
                         "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCb/vAGucNg3OJyBV6/aWEd7IK9"
                         "46GYnOT089mDzNY2zDBB9hPWwdSUYOTbDROlc3Gd4eOudeQqlnAgHB7zqwVGqWuG"
                         "vbqHWSSPpp6pMilpVVz9SMbL/1BgfhK+dKWIDYHJDRJFpBLFUpe0vq8n+8Mdgp1z"
                         "NPH3cR+rWK8zI5xF5wIDAQAB"
                         "\n-----END PUBLIC KEY-----\n";


    BIO *bio = BIO_new_mem_buf(chPublicKey, -1);
    if (!bio)
    {
        return -1;
    }
    RSA* rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL);
    if (!rsa)
    {
        return -1;
    }
    int nLen = RSA_size(rsa);
    char* pEncode = (char*)malloc(nLen + 1);
    int rc = RSA_public_encrypt(iLen, (const unsigned char*)pData, (unsigned char*)pEncode, rsa, RSA_PKCS1_PADDING);
    *pEncodeData = pEncode;
    RSA_free(rsa);
    CRYPTO_cleanup_all_ex_data();
    return rc;
}
开发者ID:baby0119,项目名称:sslapply,代码行数:35,代码来源:encryption.c


示例7: KBE_ASSERT

//-------------------------------------------------------------------------------------
int KBE_RSA::encrypt(const std::string& instr, std::string& outCertifdata)
{
	KBE_ASSERT(rsa_public != NULL);

	unsigned char* certifdata =(unsigned char*)calloc(RSA_size(static_cast<RSA*>(rsa_public)) + 1, sizeof(unsigned char));

	int certifsize = RSA_public_encrypt(instr.size(),
		(unsigned char*)instr.c_str(), certifdata, static_cast<RSA*>(rsa_public), RSA_PKCS1_OAEP_PADDING);

	if (certifsize < 0)
	{
		ERR_load_crypto_strings();
		char err[1024];
		char* errret = ERR_error_string(ERR_get_error(), err);
		ERROR_MSG(fmt::format("KBE_RSA::encrypt: RSA_public_encrypt error({} : {})\n",
			errret, err));

		free(certifdata);
		return certifsize;
	}
	
	outCertifdata.assign((const char*)certifdata, certifsize);
	free(certifdata);
	return certifsize;
}
开发者ID:5432935,项目名称:kbengine,代码行数:26,代码来源:rsa.cpp


示例8: while

//公钥加密会话密钥:
bool CRsaDesManager::RSAPubEncode(ui16 wKeyIdx, unsigned char *pcInData, unsigned long ulInLen, unsigned char *pcOutData, unsigned long *ulOutLen)
{
	if(!CheckRSAKeyIdx(wKeyIdx))
		return false;

	*ulOutLen = 0;
	unsigned long ulInTmpLen = std::min<int>(ulInLen, RSA_ENCODE_LEN_UNIT);
	unsigned long ulOutTmpLen = 0;
	while(ulInLen)
	{
		ulOutTmpLen = RSA_public_encrypt(ulInTmpLen, pcInData, pcOutData+(*ulOutLen), m_pPubRSA[wKeyIdx], 1);
		if(ulOutTmpLen <= 0)
			break;

		*ulOutLen = (*ulOutLen) + ulOutTmpLen;
		pcInData = pcInData+ulInTmpLen;
		ulInLen -= ulInTmpLen;
		ulInTmpLen = std::min<int>(ulInLen, RSA_ENCODE_LEN_UNIT);
	}

	if(ulInLen <= 0)
		return true;
	else
		return false;
}
开发者ID:furen2013,项目名称:testwork,代码行数:26,代码来源:RsaDesManager.cpp


示例9: psRsaEncryptPub

int32_t psRsaEncryptPub(psPool_t *pool, psRsaKey_t *key,
    const unsigned char *in, psSize_t inlen,
    unsigned char *out, psSize_t outlen,
    void *data)
{
    return RSA_public_encrypt(inlen, in, out, *key, RSA_PKCS1_PADDING);
}
开发者ID:vonydev,项目名称:matrixssl,代码行数:7,代码来源:rsa_openssl.c


示例10: printf

ZBuffer& RSAZCryptor::publickey_encrypt(int in_len, unsigned char* in, ZBuffer& result)
{
    if(in_len <= 0)
    {
        if(m_trace_level > 0)
            printf("Warning: input to publickey_encrypt is empty\n");

        return result;
    }

    ZBuffer onebuf(pub_size);
    int onelen = 0;
    int inc = pub_size - 42;
    int resultlen = (in_len/inc + (((in_len%inc) == 0)?0:1)) * pub_size;
    result.reserve(resultlen);
    int curpos = 0;
    unsigned char* resultptr = result.buffer();
    
    while(curpos < in_len)
    {
        int cur_inc = (in_len - curpos > inc)?inc:(in_len - curpos);

        onelen = RSA_public_encrypt(cur_inc, in + curpos, onebuf.buffer(), pub_rsa, RSA_PKCS1_OAEP_PADDING);
        if(onelen < 0)
        {
            throw_error();
        }

        memcpy(resultptr, onebuf.buffer(), onelen);
        curpos += cur_inc;
        resultptr += onelen;
    }

    return result;
}
开发者ID:elahehrashedi,项目名称:HPCC-Platform,代码行数:35,代码来源:zcrypt.cpp


示例11: rsa_encrypt

//使用公钥加密
int rsa_encrypt(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_RSA_PUBKEY(file, NULL, &ccbb, NULL))==NULL){
    if ((p_rsa=PEM_read_RSAPublicKey(file, NULL, NULL, NULL))==NULL){
        ERR_print_errors_fp(stdout);
        return 0;
    }
    rsa_len=RSA_size(p_rsa);
    if (RSA_public_encrypt(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,代码行数:26,代码来源:openssl_rsa_demo3.cpp


示例12: __ops_rsa_public_encrypt

/**
   \ingroup Core_Crypto
   \brief RSA-encrypts data
   \param out Where to write the encrypted data
   \param in Plaintext
   \param length Size of plaintext
   \param pubkey RSA Public Key
*/
int 
__ops_rsa_public_encrypt(uint8_t *out,
			const uint8_t *in,
			size_t length,
			const __ops_rsa_pubkey_t *pubkey)
{
	RSA            *orsa;
	int             n;

	/* printf("__ops_rsa_public_encrypt: length=%ld\n", length); */

	orsa = RSA_new();
	orsa->n = pubkey->n;
	orsa->e = pubkey->e;

	/* printf("len: %ld\n", length); */
	/* __ops_print_bn("n: ", orsa->n); */
	/* __ops_print_bn("e: ", orsa->e); */
	n = RSA_public_encrypt((int)length, in, out, orsa, RSA_NO_PADDING);

	if (n == -1) {
		BIO            *fd_out;

		fd_out = BIO_new_fd(fileno(stderr), BIO_NOCLOSE);
		ERR_print_errors(fd_out);
	}
	orsa->n = orsa->e = NULL;
	RSA_free(orsa);

	return n;
}
开发者ID:Mynigma,项目名称:MCryptoLib,代码行数:39,代码来源:openssl_crypto.c


示例13: rsa_encrypt

static int rsa_encrypt(u_int8_t *text, int len, u_int8_t *res)
{
	RSA *rsa;
	u_int8_t modules[256];
	u_int8_t exponent[8];
	int size;

        char n[] =
            "59dE8qLieItsH1WgjrcFRKj6eUWqi+bGLOX1HL3U3GhC/j0Qg90u3sG/1CUtwC"
            "5vOYvfDmFI6oSFXi5ELabWJmT2dKHzBJKa3k9ok+8t9ucRqMd6DZHJ2YCCLlDR"
            "KSKv6kDqnw4UwPdpOMXziC/AMj3Z/lUVX1G7WSHCAWKf1zNS1eLvqr+boEjXuB"
            "OitnZ/bDzPHrTOZz0Dew0uowxf/+sG+NCK3eQJVxqcaJ/vEHKIVd2M+5qL71yJ"
            "Q+87X6oV3eaYvt3zWZYD6z5vYTcrtij2VZ9Zmni/UAaHqn9JdsBWLUEpVviYnh"
            "imNVvYFZeCXg/IdTQ+x4IRdiXNv5hEew==";
        char e[] = "AQAB";

	rsa=RSA_new();
	size=base64_decode(n,modules);
	rsa->n=BN_bin2bn(modules,size,NULL);
	size=base64_decode(e,exponent);
	rsa->e=BN_bin2bn(exponent,size,NULL);
	size=RSA_public_encrypt(len, text, res, rsa, RSA_PKCS1_OAEP_PADDING);
	RSA_free(rsa);
	return size;
}
开发者ID:sumikawa,项目名称:raop_play,代码行数:25,代码来源:raop_client.c


示例14: ops_rsa_public_encrypt

/**
   \ingroup Core_Crypto
   \brief RSA-encrypts data
   \param out Where to write the encrypted data
   \param in Plaintext
   \param length Size of plaintext
   \param rsa RSA Public Key
*/
int ops_rsa_public_encrypt(unsigned char *out,const unsigned char *in,
			   size_t length,const ops_rsa_public_key_t *rsa)
    {
    RSA *orsa;
    int n;

    //    printf("ops_rsa_public_encrypt: length=%ld\n", length);

    orsa=RSA_new();
    orsa->n=rsa->n;
    orsa->e=rsa->e;

    //    printf("len: %ld\n", length);
    //    ops_print_bn("n: ", orsa->n);
    //    ops_print_bn("e: ", orsa->e);
    n=RSA_public_encrypt(length,in,out,orsa,RSA_NO_PADDING);

    if (n==-1)
        {
        BIO *fd_out;
        fd_out=BIO_new_fd(fileno(stderr), BIO_NOCLOSE);
        ERR_print_errors(fd_out);
        }

    orsa->n=orsa->e=NULL;
    RSA_free(orsa);

    return n;
    }
开发者ID:agl,项目名称:OpenPGP-SDK,代码行数:37,代码来源:openssl_crypto.c


示例15: RSA_size

        void RSACipher::cipher(const std::vector<unsigned char>& src, std::vector<unsigned char>& dest, const AsymmetricKey& key, KeyCompound key_compound)
        {
            const RSAKey& rsakey = static_cast<const RSAKey&>(key);

            int len = 0;
            size_t sumlen = 0;
            size_t blen = RSA_size(rsakey.d_rsa.get()) - 11;

            size_t c = (src.size() / blen) + 1;

            dest.resize(RSA_size(rsakey.d_rsa.get()) * c);

            for (size_t offset = 0; offset < src.size(); offset += blen)
            {
                if (blen + offset > src.size())
                {
                    blen = src.size() - offset;
                }

                if (key_compound == KC_PUBLIC)
                {
                    len = RSA_public_encrypt(static_cast<int>(blen), &src[offset], &dest[sumlen], rsakey.d_rsa.get(), RSA_PKCS1_PADDING);
                }
                else
                {
                    len = RSA_private_encrypt(static_cast<int>(blen), &src[offset], &dest[sumlen], rsakey.d_rsa.get(), RSA_PKCS1_PADDING);
                }

                EXCEPTION_ASSERT_WITH_LOG(len >= 0, OpenSSLException, "RSA public encrypt failed");

                sumlen += len;
            }

            dest.resize(sumlen);
        }
开发者ID:Rick0124,项目名称:liblogicalaccess,代码行数:35,代码来源:rsa_cipher.cpp


示例16: rsa_public_encrypt

static void rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA *key)
{
   u_char *inbuf, *outbuf;
   int32 len, ilen, olen;

   olen = BN_num_bytes(key->n);
   outbuf = malloc(olen);
   if (outbuf == NULL) /* oops, couldn't allocate memory */
      return;

   ilen = BN_num_bytes(in);
   inbuf = malloc(ilen);
   if (inbuf == NULL) { /* oops, couldn't allocate memory */
      SAFE_FREE(outbuf);
      return;
   }

   BN_bn2bin(in, inbuf);

   len = RSA_public_encrypt(ilen, inbuf, outbuf, key, RSA_PKCS1_PADDING);

   if (len != -1)
      BN_bin2bn(outbuf, len, out);

   free(outbuf);
   free(inbuf);
}
开发者ID:NickSampanis,项目名称:ettercap,代码行数:27,代码来源:ec_ssh.c


示例17: ssl_rsa_public_encrypt

static int ssl_rsa_public_encrypt(SESS_CERT *sc, int len, unsigned char *from,
	     unsigned char *to, int padding)
	{
	EVP_PKEY *pkey=NULL;
	int i= -1;

	if ((sc == NULL) || (sc->peer_key->x509 == NULL) ||
		((pkey=X509_get_pubkey(sc->peer_key->x509)) == NULL))
		{
		SSLerr(SSL_F_SSL_RSA_PUBLIC_ENCRYPT,SSL_R_NO_PUBLICKEY);
		return(-1);
		}
	if (pkey->type != EVP_PKEY_RSA)
		{
		SSLerr(SSL_F_SSL_RSA_PUBLIC_ENCRYPT,SSL_R_PUBLIC_KEY_IS_NOT_RSA);
		goto end;
		}

	/* we have the public key */
	i=RSA_public_encrypt(len,from,to,pkey->pkey.rsa,padding);
	if (i < 0)
		SSLerr(SSL_F_SSL_RSA_PUBLIC_ENCRYPT,ERR_R_RSA_LIB);
end:
	EVP_PKEY_free(pkey);
	return(i);
	}
开发者ID:321543223,项目名称:kbengine,代码行数:26,代码来源:s2_clnt.c


示例18: rsa_public_encrypt

void
rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA *key)
{
	u_char *inbuf, *outbuf;
	int len, ilen, olen;

	if (BN_num_bits(key->e) < 2 || !BN_is_odd(key->e))
		fatal("rsa_public_encrypt() exponent too small or not odd");

	olen = BN_num_bytes(key->n);
	outbuf = xmalloc(olen);

	ilen = BN_num_bytes(in);
	inbuf = xmalloc(ilen);
	BN_bn2bin(in, inbuf);

	if ((len = RSA_public_encrypt(ilen, inbuf, outbuf, key,
	    RSA_PKCS1_PADDING)) <= 0)
		fatal("rsa_public_encrypt() failed");

	if (BN_bin2bn(outbuf, len, out) == NULL)
		fatal("rsa_public_encrypt: BN_bin2bn failed");

	explicit_bzero(outbuf, olen);
	explicit_bzero(inbuf, ilen);
	free(outbuf);
	free(inbuf);
}
开发者ID:Alkzndr,项目名称:freebsd,代码行数:28,代码来源:rsa.c


示例19: ERR_load_crypto_strings

biginteger OpenSSLRSAPermutation::computeRSA(biginteger elementP) {
	ERR_load_crypto_strings();
	//SSL_load_error_strings();
	// Seed the random geneartor.
#ifdef _WIN32
	RAND_screen(); // only defined for windows, reseeds from screen contents
#else
	RAND_poll(); // reseeds using hardware state (clock, interrupts, etc).
#endif

	// Allocate a new byte array to hold the output.
	int size = RSA_size(rsa);
	std::shared_ptr<byte> ret(new byte[size], std::default_delete<byte[]>());

	size_t encodedSize = bytesCount(elementP);
	std::shared_ptr<byte> encodedBi(new byte[encodedSize], std::default_delete<byte[]>());
	encodeBigInteger(elementP, encodedBi.get(), encodedSize);
	int success = RSA_public_encrypt(encodedSize, encodedBi.get(), ret.get(), rsa, RSA_NO_PADDING);
	if (-1 == success)
	{
		string error(ERR_reason_error_string(ERR_get_error()));
		throw runtime_error("failed to compute rsa " + error);
	}
	biginteger result = decodeBigInteger(ret.get(), size);
	return result;
}
开发者ID:Perseus14,项目名称:scapi,代码行数:26,代码来源:TrapdoorPermutationOpenSSL.cpp


示例20: gcry_sexp_build

STRING *ssh_encrypt_rsa1(SSH_SESSION *session, STRING *data, PUBLIC_KEY *key){
    int len=string_len(data);
#ifdef HAVE_LIBGCRYPT
    STRING *ret;
    gcry_sexp_t ret_sexp;
    gcry_sexp_t data_sexp;
    const char *tmp;
    size_t size;
    gcry_sexp_build(&data_sexp,NULL,"(data(flags pkcs1)(value %b))",len,data->string);
    gcry_pk_encrypt(&ret_sexp,data_sexp,key->rsa_pub);
    gcry_sexp_release(data_sexp);
    data_sexp=gcry_sexp_find_token(ret_sexp,"a",0);
    tmp=gcry_sexp_nth_data(data_sexp,1,&size);
    if (*tmp == 0)
    {
      size--;
      tmp++;
    }
    ret=string_new(size);
    string_fill(ret,(char *)tmp,size);
    gcry_sexp_release(ret_sexp);
#elif defined HAVE_LIBCRYPTO
    int flen=RSA_size(key->rsa_pub);
    STRING *ret=string_new(flen);
    RSA_public_encrypt(len,data->string,ret->string,key->rsa_pub,
            RSA_PKCS1_PADDING);
#endif
    return ret;
}
开发者ID:BackupTheBerlios,项目名称:libssh-svn,代码行数:29,代码来源:keys.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ RSA_sign函数代码示例发布时间:2022-05-30
下一篇:
C++ RSA_public_decrypt函数代码示例发布时间: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