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

C++ EVP_Digest函数代码示例

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

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



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

示例1: X509_ocspid_print

int X509_ocspid_print(BIO *bp, X509 *x)
{
    unsigned char *der = NULL;
    unsigned char *dertmp;
    int derlen;
    int i;
    unsigned char SHA1md[SHA_DIGEST_LENGTH];

    /*
     * display the hash of the subject as it would appear in OCSP requests
     */
    if (BIO_printf(bp, "        Subject OCSP hash: ") <= 0)
        goto err;
    derlen = i2d_X509_NAME(x->cert_info->subject, NULL);
    if ((der = dertmp = (unsigned char *)OPENSSL_malloc(derlen)) == NULL)
        goto err;
    i2d_X509_NAME(x->cert_info->subject, &dertmp);

    if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL))
        goto err;
    for (i = 0; i < SHA_DIGEST_LENGTH; i++) {
        if (BIO_printf(bp, "%02X", SHA1md[i]) <= 0)
            goto err;
    }
    OPENSSL_free(der);
    der = NULL;

    /*
     * display the hash of the public key as it would appear in OCSP requests
     */
    if (BIO_printf(bp, "\n        Public key OCSP hash: ") <= 0)
        goto err;

    if (!EVP_Digest(x->cert_info->key->public_key->data,
                    x->cert_info->key->public_key->length,
                    SHA1md, NULL, EVP_sha1(), NULL))
        goto err;
    for (i = 0; i < SHA_DIGEST_LENGTH; i++) {
        if (BIO_printf(bp, "%02X", SHA1md[i]) <= 0)
            goto err;
    }
    BIO_printf(bp, "\n");

    return (1);
 err:
    if (der != NULL)
        OPENSSL_free(der);
    return (0);
}
开发者ID:alagoutte,项目名称:proto-quic,代码行数:49,代码来源:t_x509.c


示例2: EVP_Digest

string& WS::ComputeKey(string& key) {
	key.append("258EAFA5-E914-47DA-95CA-C5AB0DC85B11"); // WEBSOCKET_GUID
	UInt8 temp[20];
	EVP_Digest(key.c_str(),key.size(),temp,NULL,EVP_sha1(),NULL);

	return Util::ToBase64(temp, sizeof(temp), key); 
}
开发者ID:8088,项目名称:MonaServer,代码行数:7,代码来源:WS.cpp


示例3: main

int main(int argc, char *argv[])
	{
	int i,err=0;
	unsigned char **P,**R;
	char *p;
	unsigned char md[RIPEMD160_DIGEST_LENGTH];

	P=(unsigned char **)test;
	R=(unsigned char **)ret;
	i=1;
	while (*P != NULL)
		{
#ifdef CHARSET_EBCDIC
		ebcdic2ascii((char *)*P, (char *)*P, strlen((char *)*P));
#endif
		EVP_Digest(&(P[0][0]),strlen((char *)*P),md,NULL,EVP_ripemd160(), NULL);
		p=pt(md);
		if (strcmp(p,(char *)*R) != 0)
			{
			printf("error calculating RIPEMD160 on '%s'\n",*P);
			printf("got %s instead of %s\n",p,*R);
			err++;
			}
		else
			printf("test %d ok\n",i);
		i++;
		R++;
		P++;
		}
	EXIT(err);
	return(0);
	}
开发者ID:174high,项目名称:openssl-0.9.8e_linux_porting,代码行数:32,代码来源:rmdtest.c


示例4: main

int main(int argc, char **argv) {
  size_t i, j;
  uint8_t md[SHA_DIGEST_LENGTH];
  char md_hex[sizeof(md) * 2 + 1];
  int ok = 1;

  CRYPTO_library_init();

  for (i = 0; test[i] != NULL; i++) {
    EVP_Digest(test[i], strlen(test[i]), md, NULL, EVP_sha1(), NULL);
    for (j = 0; j < sizeof(md); j++) {
      sprintf(&md_hex[j * 2], "%02x", md[j]);
    }

    if (strcmp(md_hex, expected[i]) != 0) {
      fprintf(stderr, "#%u: got %s, wanted %s\n", (unsigned)i, md_hex,
              expected[i]);
      ok = 0;
    }
  }

  ok &= test_incremental();

  if (ok) {
    printf("PASS\n");
  }

  return ok ? 0 : 1;
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:29,代码来源:sha1_test.c


示例5: md_full

int
md_full (const EVP_MD *kt, const uint8_t *src, int src_len, uint8_t *dst)
{
  unsigned int in_md_len = 0;

  return EVP_Digest(src, src_len, dst, &in_md_len, kt, NULL);
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:7,代码来源:crypto_openssl.c


示例6: throw

ByteArray PublicKey::getKeyIdentifier() throw (EncodeException)
{
	ByteArray ret;
	unsigned int size;
	X509_PUBKEY *pubkey = NULL;
	
	if(X509_PUBKEY_set(&pubkey, this->key) == 0)
	{
		throw EncodeException(EncodeException::UNKNOWN, "PublicKey::getKeyIdentifier");
	}
			
	ret = ByteArray(EVP_MAX_MD_SIZE);
	EVP_Digest(pubkey->public_key->data, pubkey->public_key->length, ret.getDataPointer(), &size, EVP_sha1(), NULL);
	ret = ByteArray(ret.getDataPointer(), size);

	X509_PUBKEY_free(pubkey);
	
	return ret;
	
	//return ByteArray(digest, digestLen);

	/*	ByteArray der = this->getDerEncoded();
	MessageDigest md(MessageDigest::SHA1);
	
	MessageDigest::loadMessageDigestAlgorithms();
	
	return md.doFinal(der);*/
}
开发者ID:GNakayama,项目名称:libcryptosec,代码行数:28,代码来源:PublicKey.cpp


示例7: ASN1_digest

int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
                unsigned char *md, unsigned int *len)
{
    int inl;
    unsigned char *str, *p;

    inl = i2d(data, NULL);
    if (inl <= 0) {
        ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_INTERNAL_ERROR);
        return 0;
    }
    if ((str = OPENSSL_malloc(inl)) == NULL) {
        ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_MALLOC_FAILURE);
        return 0;
    }
    p = str;
    i2d(data, &p);

    if (!EVP_Digest(str, inl, md, len, type, NULL)) {
        OPENSSL_free(str);
        return 0;
    }
    OPENSSL_free(str);
    return 1;
}
开发者ID:Ana06,项目名称:openssl,代码行数:25,代码来源:a_digest.c


示例8: OPENSSL_HEADER

CK_RV PKCS11_Digest_OpenSSL::Digest(Cryptoki_Session_Context* pSessionCtx, CK_BYTE_PTR pData, CK_ULONG ulDataLen, CK_BYTE_PTR pDigest, CK_ULONG_PTR pulDigestLen)
{
    OPENSSL_HEADER();
    
    UINT32             digestLen = *pulDigestLen;
    OpenSSLDigestData* pDigData;

    if(pSessionCtx == NULL || pSessionCtx->DigestCtx == NULL) return CKR_SESSION_CLOSED;

    pDigData = (OpenSSLDigestData*)pSessionCtx->DigestCtx;

    if(pDigData->HmacKey != NULL)
    {
        OPENSSL_CHECKRESULT(HMAC_Update(&pDigData->HmacCtx, pData  , ulDataLen ));
        OPENSSL_CHECKRESULT(HMAC_Final (&pDigData->HmacCtx, pDigest, &digestLen));
    }
    else
    {
        OPENSSL_CHECKRESULT(EVP_Digest(pData, ulDataLen, pDigest, &digestLen, pDigData->CurrentCtx.digest, NULL));
    }

    *pulDigestLen = digestLen;

    OPENSSL_CLEANUP();
    
    TINYCLR_SSL_FREE(pDigData);
    pSessionCtx->DigestCtx = NULL;
    
    OPENSSL_RETURN();
}
开发者ID:AustinWise,项目名称:Netduino-Micro-Framework,代码行数:30,代码来源:OpenSSL_PKCS11_digest.cpp


示例9: main

int main(int argc, char *argv[])
	{
	int i,err=0;
	char **P,**R;
	char *p;
	unsigned char md[RIPEMD160_DIGEST_LENGTH];

	P=test;
	R=ret;
	i=1;
	while (*P != NULL)
		{
#ifdef CHARSET_EBCDIC
		ebcdic2ascii((char *)*P, (char *)*P, TINYCLR_SSL_STRLEN((char *)*P));
#endif
		EVP_Digest(&(P[0][0]),TINYCLR_SSL_STRLEN((char *)*P),md,NULL,EVP_ripemd160(), NULL);
		p=pt(md);
		if (TINYCLR_SSL_STRCMP(p,(char *)*R) != 0)
			{
			TINYCLR_SSL_PRINTF("error calculating RIPEMD160 on '%s'\n",*P);
			TINYCLR_SSL_PRINTF("got %s instead of %s\n",p,*R);
			err++;
			}
		else
			TINYCLR_SSL_PRINTF("test %d ok\n",i);
		i++;
		R++;
		P++;
		}
	EXIT(err);
	return(0);
	}
开发者ID:AustinWise,项目名称:Netduino-Micro-Framework,代码行数:32,代码来源:rmdtest.cpp


示例10: main

int main(int argc, char *argv[])
{
    int i, err = 0;
    char **P, **R;
    char *p;
    unsigned char md[MD5_DIGEST_LENGTH];

    P = test;
    R = ret;
    i = 1;
    while (*P != NULL) {
        EVP_Digest(&(P[0][0]), strlen((char *)*P), md, NULL, EVP_md5(), NULL);
        p = pt(md);
        if (strcmp(p, (char *)*R) != 0) {
            printf("error calculating MD5 on '%s'\n", *P);
            printf("got %s instead of %s\n", p, *R);
            err++;
        } else
            printf("test %d ok\n", i);
        i++;
        R++;
        P++;
    }

# ifdef OPENSSL_SYS_NETWARE
    if (err)
        printf("ERROR: %d\n", err);
# endif
    EXIT(err);
}
开发者ID:TheTypoMaster,项目名称:openssl,代码行数:30,代码来源:md5test.c


示例11: ca_subjectpubkey_digest

int
ca_subjectpubkey_digest(X509 *x509, uint8_t *md, unsigned int *size)
{
	uint8_t		*buf = NULL;
	int		 buflen;

	if (*size < SHA_DIGEST_LENGTH)
		return (-1);

	/*
	 * Generate a SHA-1 digest of the Subject Public Key Info
	 * element in the X.509 certificate, an ASN.1 sequence
	 * that includes the public key type (eg. RSA) and the
	 * public key value (see 3.7 of RFC4306).
	 */
	buflen = i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x509), &buf);
	if (!buflen)
		return (-1);
	if (!EVP_Digest(buf, buflen, md, size, EVP_sha1(), NULL)) {
		free(buf);
		return (-1);
	}
	free(buf);

	return (0);
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:26,代码来源:ca.c


示例12: X509_pubkey_digest

int X509_pubkey_digest(const X509 *data, const EVP_MD *type, unsigned char *md,
	     unsigned int *len)
	{
	ASN1_BIT_STRING *key;
	key = X509_get0_pubkey_bitstr(data);
	if(!key) return 0;
	return EVP_Digest(key->data, key->length, md, len, type, NULL);
	}
开发者ID:krunalsoni01,项目名称:src,代码行数:8,代码来源:x_all.c


示例13: main

int main(int argc, char *argv[])
	{
	int i,err=0;
	unsigned char **P,**R;
	static unsigned char buf[1000];
	char *p,*r;
	EVP_MD_CTX c;
	unsigned char md[SHA_DIGEST_LENGTH];

#ifdef CHARSET_EBCDIC
	ebcdic2ascii(test[0], test[0], strlen(test[0]));
	ebcdic2ascii(test[1], test[1], strlen(test[1]));
#endif

	EVP_MD_CTX_init(&c);
	P=(unsigned char **)test;
	R=(unsigned char **)ret;
	i=1;
	while (*P != NULL)
		{
		EVP_Digest(*P,(unsigned long)strlen((char *)*P),md,NULL,EVP_sha(), NULL);
		p=pt(md);
		if (strcmp(p,(char *)*R) != 0)
			{
			printf("error calculating SHA on '%s'\n",*P);
			printf("got %s instead of %s\n",p,*R);
			err++;
			}
		else
			printf("test %d ok\n",i);
		i++;
		R++;
		P++;
		}

	memset(buf,'a',1000);
#ifdef CHARSET_EBCDIC
	ebcdic2ascii(buf, buf, 1000);
#endif /*CHARSET_EBCDIC*/
	EVP_DigestInit_ex(&c,EVP_sha(), NULL);
	for (i=0; i<1000; i++)
		EVP_DigestUpdate(&c,buf,1000);
	EVP_DigestFinal_ex(&c,md,NULL);
	p=pt(md);

	r=bigret;
	if (strcmp(p,r) != 0)
		{
		printf("error calculating SHA on '%s'\n",p);
		printf("got %s instead of %s\n",p,r);
		err++;
		}
	else
		printf("test 3 ok\n");
	EVP_MD_CTX_cleanup(&c);
	EXIT(err);
	return(0);
	}
开发者ID:FelipeFernandes1988,项目名称:Alice-1121-Modem,代码行数:58,代码来源:shatest.c


示例14: main

int main(int argc, char *argv[])
{
    int i, err = 0;
    char **P, **R;
    static unsigned char buf[1000];
    char *p, *r;
    EVP_MD_CTX *c;
    unsigned char md[SHA_DIGEST_LENGTH];

#ifdef CHARSET_EBCDIC
    ebcdic2ascii(test[0], test[0], strlen(test[0]));
    ebcdic2ascii(test[1], test[1], strlen(test[1]));
#endif

    c = EVP_MD_CTX_new();
    P = test;
    R = ret;
    i = 1;
    while (*P != NULL) {
        EVP_Digest(*P, strlen((char *)*P), md, NULL, EVP_sha1(), NULL);
        p = pt(md);
        if (strcmp(p, (char *)*R) != 0) {
            printf("error calculating SHA1 on '%s'\n", *P);
            printf("got %s instead of %s\n", p, *R);
            err++;
        } else
            printf("test %d ok\n", i);
        i++;
        R++;
        P++;
    }

    memset(buf, 'a', 1000);
#ifdef CHARSET_EBCDIC
    ebcdic2ascii(buf, buf, 1000);
#endif                         /* CHARSET_EBCDIC */
    EVP_DigestInit_ex(c, EVP_sha1(), NULL);
    for (i = 0; i < 1000; i++)
        EVP_DigestUpdate(c, buf, 1000);
    EVP_DigestFinal_ex(c, md, NULL);
    p = pt(md);

    r = bigret;
    if (strcmp(p, r) != 0) {
        printf("error calculating SHA1 on 'a' * 1000\n");
        printf("got %s instead of %s\n", p, r);
        err++;
    } else
        printf("test 3 ok\n");

#ifdef OPENSSL_SYS_NETWARE
    if (err)
        printf("ERROR: %d\n", err);
#endif
    EVP_MD_CTX_free(c);
    EXIT(err);
    return (0);
}
开发者ID:DarovskikhAndrei,项目名称:openssl,代码行数:58,代码来源:sha1test.c


示例15: ASN1_OBJECT_free

OCSP_CERTID *OCSP_cert_id_new (const EVP_MD * dgst,
                               X509_NAME * issuerName, ASN1_BIT_STRING * issuerKey, ASN1_INTEGER * serialNumber)
{
    int nid;

    unsigned int i;

    X509_ALGOR *alg;

    OCSP_CERTID *cid = NULL;

    unsigned char md[EVP_MAX_MD_SIZE];

    if (!(cid = OCSP_CERTID_new ()))
        goto err;

    alg = cid->hashAlgorithm;
    if (alg->algorithm != NULL)
        ASN1_OBJECT_free (alg->algorithm);
    if ((nid = EVP_MD_type (dgst)) == NID_undef)
    {
        OCSPerr (OCSP_F_OCSP_CERT_ID_NEW, OCSP_R_UNKNOWN_NID);
        goto err;
    }
    if (!(alg->algorithm = OBJ_nid2obj (nid)))
        goto err;
    if ((alg->parameter = ASN1_TYPE_new ()) == NULL)
        goto err;
    alg->parameter->type = V_ASN1_NULL;

    if (!X509_NAME_digest (issuerName, dgst, md, &i))
        goto digerr;
    if (!(ASN1_OCTET_STRING_set (cid->issuerNameHash, md, i)))
        goto err;

    /* Calculate the issuerKey hash, excluding tag and length */
    if (!EVP_Digest (issuerKey->data, issuerKey->length, md, &i, dgst, NULL))
        goto err;

    if (!(ASN1_OCTET_STRING_set (cid->issuerKeyHash, md, i)))
        goto err;

    if (serialNumber)
    {
        ASN1_INTEGER_free (cid->serialNumber);
        if (!(cid->serialNumber = ASN1_INTEGER_dup (serialNumber)))
            goto err;
    }
    return cid;
  digerr:
    OCSPerr (OCSP_F_OCSP_CERT_ID_NEW, OCSP_R_DIGEST_ERR);
  err:
    if (cid)
        OCSP_CERTID_free (cid);
    return NULL;
}
开发者ID:274914765,项目名称:C,代码行数:56,代码来源:ocsp_lib.c


示例16: ECDSA_Sign

bool ECDSA_Sign(COSE * pSigner, int index, const cn_cbor * pKey, int cbitDigest, const byte * rgbToSign, size_t cbToSign, cose_errback * perr)
{
	EC_KEY * eckey = NULL;
	byte rgbDigest[EVP_MAX_MD_SIZE];
	unsigned int cbDigest = sizeof(rgbDigest);
	byte  * pbSig = NULL;
	const EVP_MD * digest;
#ifdef USE_CBOR_CONTEXT
	cn_cbor_context * context = &pSigner->m_allocContext;
#endif
	cn_cbor * p = NULL;
	ECDSA_SIG * psig = NULL;
	cn_cbor_errback cbor_error;
	int cbR;
	byte rgbSig[66];
	int cb;
	
	eckey = ECKey_From(pKey, &cbR, perr);
	if (eckey == NULL) {
	errorReturn:
		if (p != NULL) CN_CBOR_FREE(p, context);
		if (eckey != NULL) EC_KEY_free(eckey);
		return false;
	}

	switch (cbitDigest) {
	case 256: digest = EVP_sha256(); break;
	case 512: digest = EVP_sha512(); break;
	case 384: digest = EVP_sha384(); break;
	default:
		FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER);
	}

	EVP_Digest(rgbToSign, cbToSign, rgbDigest, &cbDigest, digest, NULL);

	psig = ECDSA_do_sign(rgbDigest, cbDigest, eckey);
	CHECK_CONDITION(psig != NULL, COSE_ERR_CRYPTO_FAIL);

	pbSig = COSE_CALLOC(cbR, 2, context);
	CHECK_CONDITION(pbSig != NULL, COSE_ERR_OUT_OF_MEMORY);

	cb = BN_bn2bin(psig->r, rgbSig);
	CHECK_CONDITION(cb <= cbR, COSE_ERR_INVALID_PARAMETER);
	memcpy(pbSig + cbR - cb, rgbSig, cb);

	cb = BN_bn2bin(psig->s, rgbSig);
	CHECK_CONDITION(cb <= cbR, COSE_ERR_INVALID_PARAMETER);
	memcpy(pbSig + 2*cbR - cb, rgbSig, cb);

	p = cn_cbor_data_create(pbSig, cbR*2, CBOR_CONTEXT_PARAM_COMMA &cbor_error);
	CHECK_CONDITION_CBOR(p != NULL, cbor_error);

	CHECK_CONDITION(_COSE_array_replace(pSigner, p, index, CBOR_CONTEXT_PARAM_COMMA NULL), COSE_ERR_CBOR);
	
	return true;
}
开发者ID:KaneRoot,项目名称:COSE-C,代码行数:56,代码来源:openssl.c


示例17: CPK_PUBLIC_PARAMS_digest

int CPK_PUBLIC_PARAMS_digest(CPK_PUBLIC_PARAMS *params, const EVP_MD *md,
	unsigned char *dgst, unsigned int *dgstlen)
{
	if (!EVP_Digest(M_ASN1_STRING_data(params->public_factors),
		M_ASN1_STRING_length(params->public_factors),
		dgst, dgstlen, md, NULL)) {
		return 0;
	}
	return 1;
}
开发者ID:LiTianjue,项目名称:GmSSL,代码行数:10,代码来源:cpk_lib.c


示例18: openconnect_sha1

int openconnect_sha1(unsigned char *result, void *data, int len)
{
	EVP_MD_CTX c;

	EVP_MD_CTX_init(&c);
	EVP_Digest(data, len, result, NULL, EVP_sha1(), NULL);
	EVP_MD_CTX_cleanup(&c);

	return 0;
}
开发者ID:shahrdad1,项目名称:openconnect,代码行数:10,代码来源:openssl.c


示例19: EVP_Digest

/**
 * EM_AES::set_key()
 * 设置AES加密密钥
 * 
 * @param string key
 * @return void
 */
void EM_AES::set_key(const string & key)
{
	this->m_key_str = key;
	
	unsigned char md[MD5_DIGEST_LENGTH];
	
	EVP_Digest(key.c_str(), (size_t)key.length(), md, NULL, EVP_md5(), NULL);

	strncpy((char*)&this->m_key, (char*)&md, EM_AES_KEY_SIZE/8); 
}
开发者ID:Igneel,项目名称:crypto-tester,代码行数:17,代码来源:aes.cpp


示例20: CPK_MASTER_SECRET_digest

int CPK_MASTER_SECRET_digest(CPK_MASTER_SECRET *master, const EVP_MD *md,
	unsigned char *dgst, unsigned int *dgstlen)
{
	if (!EVP_Digest(M_ASN1_STRING_data(master->secret_factors),
		M_ASN1_STRING_length(master->secret_factors),
		dgst, dgstlen, md, NULL)) {
		return 0;
	}
	return 1;
}
开发者ID:LiTianjue,项目名称:GmSSL,代码行数:10,代码来源:cpk_lib.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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