本文整理汇总了C++中EVP_EncodeBlock函数的典型用法代码示例。如果您正苦于以下问题:C++ EVP_EncodeBlock函数的具体用法?C++ EVP_EncodeBlock怎么用?C++ EVP_EncodeBlock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EVP_EncodeBlock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: varPtr
BSTR CBoxEncoding::Base64Encode(VARIANT& var)
{
CBoxBinPtr varPtr(var);
CStringA str;
LPSTR pstr;
int strSize;
int nPos, i;
strSize = ((varPtr.m_nSize + 2) / 3) * 4;
strSize += (strSize / 64) * 2;
pstr = str.GetBuffer(strSize);
for(i = 0, nPos = 0; i < varPtr.m_nSize; i += 48)
if(varPtr.m_nSize - i > 48)
{
EVP_EncodeBlock((unsigned char*)pstr + nPos, (unsigned char*)varPtr + i, 48);
nPos += 64;
pstr[nPos ++] = '\r';
pstr[nPos ++] = '\n';
}else
EVP_EncodeBlock((unsigned char*)pstr + nPos, (unsigned char*)varPtr + i, varPtr.m_nSize - i);
str.ReleaseBuffer(strSize);
return str.AllocSysString();
}
开发者ID:2Quico,项目名称:netbox,代码行数:25,代码来源:BoxEncoding.cpp
示例2: ship_encode_base64
/* Encode something to base-64 */
char *
ship_encode_base64(unsigned char *input, int length)
{
char *ret = NULL;
unsigned char in[48];
int blen, i=0, ilen, len=0, olen=0;
blen = (((length + 2) / 3) * 4) + 3;
ASSERT_TRUE(ret = (char *)malloc(blen), err);
while(i<length){
ilen = (i+48<length)?48:length-i;
memcpy (in, input, ilen);
input += ilen;
i += ilen;
/* Each 48-byte text should encode to 64-byte binary */
len = EVP_EncodeBlock((unsigned char*)ret+olen, in, ilen);
olen += len;
}
ret[olen] = '\0';
err:
return ret;
}
开发者ID:sksushilkumar,项目名称:p2pship,代码行数:28,代码来源:ship_crypto.c
示例3: EVP_EncodeBlock
int WXBizMsgCrypt::EncodeBase64(const std::string sSrc, std::string & sTarget)
{
if(0 == sSrc.size() || kMaxBase64Size < sSrc.size())
{
return -1;
}
uint32_t iBlockNum = sSrc.size() / 3;
if (iBlockNum * 3 != sSrc.size())
{
iBlockNum++;
}
uint32_t iOutBufSize = iBlockNum * 4 + 1;
char * pcOutBuf = (char*)malloc( iOutBufSize);
if(NULL == pcOutBuf)
{
return -1;
}
int iReturn = 0;
int ret = EVP_EncodeBlock((unsigned char*)pcOutBuf, (const unsigned char*)sSrc.c_str(), sSrc.size());
if (ret > 0 && ret < (int)iOutBufSize)
{
sTarget.assign(pcOutBuf,ret);
}
else
{
iReturn = -1;
}
FREE_PTR(pcOutBuf);
return iReturn;
}
开发者ID:lgyhitler,项目名称:node-weixin-crypto,代码行数:33,代码来源:WXBizMsgCrypt.cpp
示例4: PEM_SignFinal
int
PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
EVP_PKEY *pkey)
{
unsigned char *m;
int i, ret = 0;
unsigned int m_len;
m = malloc(EVP_PKEY_size(pkey) + 2);
if (m == NULL) {
PEMerr(PEM_F_PEM_SIGNFINAL, ERR_R_MALLOC_FAILURE);
goto err;
}
if (EVP_SignFinal(ctx, m, &m_len, pkey) <= 0)
goto err;
i = EVP_EncodeBlock(sigret, m, m_len);
*siglen = i;
ret = 1;
err:
/* ctx has been zeroed by EVP_SignFinal() */
free(m);
return (ret);
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:26,代码来源:pem_sign.c
示例5: NETSCAPE_SPKI_b64_encode
char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki)
{
unsigned char *der_spki, *p;
char *b64_str;
size_t b64_len;
int der_len;
der_len = i2d_NETSCAPE_SPKI(spki, NULL);
if (!EVP_EncodedLength(&b64_len, der_len))
{
OPENSSL_PUT_ERROR(X509, NETSCAPE_SPKI_b64_encode, ERR_R_OVERFLOW);
return NULL;
}
der_spki = OPENSSL_malloc(der_len);
if (der_spki == NULL) {
OPENSSL_PUT_ERROR(X509, NETSCAPE_SPKI_b64_encode, ERR_R_MALLOC_FAILURE);
return NULL;
}
b64_str = OPENSSL_malloc(b64_len);
if (b64_str == NULL) {
OPENSSL_free(der_spki);
OPENSSL_PUT_ERROR(X509, NETSCAPE_SPKI_b64_encode, ERR_R_MALLOC_FAILURE);
return NULL;
}
p = der_spki;
i2d_NETSCAPE_SPKI(spki, &p);
EVP_EncodeBlock((unsigned char *)b64_str, der_spki, der_len);
OPENSSL_free(der_spki);
return b64_str;
}
开发者ID:HungMingWu,项目名称:libquic,代码行数:29,代码来源:x509spki.c
示例6: memset
char *base64(const unsigned char *input, int length)
{
char *buffer = (char*)xmalloc(length*2);
memset(buffer, 0, length*2);
EVP_EncodeBlock((unsigned char*)buffer, input, length);
return buffer;
}
开发者ID:freehaha,项目名称:libfreemsn,代码行数:7,代码来源:msnlib.c
示例7: _SSL_do_cipher_base64
static char *
_SSL_do_cipher_base64(char *buf, int buf_len, char *key, int operation)
{
char *pt;
char *pt2;
int i;
if (operation) {
i = _SSL_do_cipher(buf, buf_len, key, operation, &pt);
pt2 = mmalloc(i * 2 + 1); /* + NULL */
memset(pt2, 0, i * 2 + 1); /* FIXME: need it? */
if ((i = EVP_EncodeBlock(pt2, pt, i)) == -1) {
fprintf(stderr, "_SSL_do_cipher_base64 :: EVP_EncodeBlock failed\n");
exit(1);
}
fprintf(stderr, "_SSL_do_cipher_base64 :: EVP_EncodeBlock %d [%24s]\n", i, key);
} else {
pt = mmalloc(buf_len / 2 * 2 + 1); /* + NULL */
memset(pt, 0, buf_len / 2 * 2 + 1); /* FIXME: need it? */
if ((i = EVP_DecodeBlock(pt, buf, buf_len)) == -1) {
fprintf(stderr, "_SSL_do_cipher_base64 :: EVP_DecodeBlock failed\n");
exit(1);
}
fprintf(stderr, "_SSL_do_cipher_base64 :: EVP_DecodeBlock %d [%24s]\n", i, key);
i -= i % 8; /* cut padding */
i = _SSL_do_cipher(pt, i, key, operation, &pt2);
}
free (pt);
return (pt2);
}
开发者ID:UIKit0,项目名称:picogui,代码行数:32,代码来源:ssl.c
示例8: EVP_EncodeUpdate
void
EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
const unsigned char *in, int inl)
{
int i, j;
size_t total = 0;
*outl = 0;
if (inl == 0)
return;
OPENSSL_assert(ctx->length <= (int)sizeof(ctx->enc_data));
if (ctx->length - ctx->num > inl) {
memcpy(&(ctx->enc_data[ctx->num]), in, inl);
ctx->num += inl;
return;
}
if (ctx->num != 0) {
i = ctx->length - ctx->num;
memcpy(&(ctx->enc_data[ctx->num]), in, i);
in += i;
inl -= i;
j = EVP_EncodeBlock(out, ctx->enc_data, ctx->length);
ctx->num = 0;
out += j;
*(out++) = '\n';
*out = '\0';
total = j + 1;
}
while (inl >= ctx->length && total <= INT_MAX) {
j = EVP_EncodeBlock(out, in, ctx->length);
in += ctx->length;
inl -= ctx->length;
out += j;
*(out++) = '\n';
*out = '\0';
total += j + 1;
}
if (total > INT_MAX) {
/* Too much output data! */
*outl = 0;
return;
}
if (inl != 0)
memcpy(&(ctx->enc_data[0]), in, inl);
ctx->num = inl;
*outl = total;
}
开发者ID:bbbrumley,项目名称:openbsd,代码行数:47,代码来源:encode.c
示例9: EVP_EncodeUpdate
void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, uint8_t *out, int *out_len,
const uint8_t *in, size_t in_len) {
size_t total = 0;
*out_len = 0;
if (in_len == 0) {
return;
}
assert(ctx->length <= sizeof(ctx->enc_data));
assert(ctx->num < ctx->length);
if (ctx->length - ctx->num > in_len) {
memcpy(&ctx->enc_data[ctx->num], in, in_len);
ctx->num += in_len;
return;
}
if (ctx->num != 0) {
size_t todo = ctx->length - ctx->num;
memcpy(&ctx->enc_data[ctx->num], in, todo);
in += todo;
in_len -= todo;
size_t encoded = EVP_EncodeBlock(out, ctx->enc_data, ctx->length);
ctx->num = 0;
out += encoded;
*(out++) = '\n';
*out = '\0';
total = encoded + 1;
}
while (in_len >= ctx->length) {
size_t encoded = EVP_EncodeBlock(out, in, ctx->length);
in += ctx->length;
in_len -= ctx->length;
out += encoded;
*(out++) = '\n';
*out = '\0';
total += encoded + 1;
}
if (in_len != 0) {
memcpy(&ctx->enc_data[0], in, in_len);
}
ctx->num = in_len;
*out_len = total;
}
开发者ID:Cyril2004,项目名称:proto-quic,代码行数:47,代码来源:base64.c
示例10: PEM_SealInit
int
PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk)
{
unsigned char key[EVP_MAX_KEY_LENGTH];
int ret = -1;
int i, j, max = 0;
char *s = NULL;
/*
* Make sure ctx is properly initialized so that we can always pass
* it to PEM_ENCODE_SEAL_CTX_cleanup() in the error path.
*/
EVP_EncodeInit(&ctx->encode);
EVP_MD_CTX_init(&ctx->md);
EVP_CIPHER_CTX_init(&ctx->cipher);
for (i = 0; i < npubk; i++) {
if (pubk[i]->type != EVP_PKEY_RSA) {
PEMerror(PEM_R_PUBLIC_KEY_NO_RSA);
goto err;
}
j = RSA_size(pubk[i]->pkey.rsa);
if (j > max)
max = j;
}
s = reallocarray(NULL, max, 2);
if (s == NULL) {
PEMerror(ERR_R_MALLOC_FAILURE);
goto err;
}
if (!EVP_SignInit(&ctx->md, md_type))
goto err;
ret = EVP_SealInit(&ctx->cipher, type, ek, ekl, iv, pubk, npubk);
if (ret <= 0)
goto err;
/* base64 encode the keys */
for (i = 0; i < npubk; i++) {
j = EVP_EncodeBlock((unsigned char *)s, ek[i],
RSA_size(pubk[i]->pkey.rsa));
ekl[i] = j;
memcpy(ek[i], s, j + 1);
}
ret = npubk;
if (0) {
err:
PEM_ENCODE_SEAL_CTX_cleanup(ctx);
}
free(s);
explicit_bzero(key, sizeof(key));
return (ret);
}
开发者ID:MiKTeX,项目名称:miktex,代码行数:57,代码来源:pem_seal.c
示例11: auth_cram_md5
/*
* Authenticate to the server with the Challenge-Response Authentication
* Mechanism (CRAM). The authentication type associated with CRAM is
* "CRAM-MD5".
*/
int
auth_cram_md5(session *ssn, const char *user, const char *pass)
{
int t;
size_t n;
unsigned int i;
unsigned char *chal, *resp, *out, *buf;
unsigned char md[EVP_MAX_MD_SIZE], mdhex[EVP_MAX_MD_SIZE * 2 + 1];
unsigned int mdlen;
HMAC_CTX hmac;
if ((t = imap_authenticate(ssn, "CRAM-MD5")) == -1)
return -1;
if (response_authenticate(ssn, t, &chal) ==
STATUS_RESPONSE_CONTINUE) {
n = strlen((char *)(chal)) * 3 / 4 + 1;
resp = (unsigned char *)xmalloc(n * sizeof(char));
memset(resp, 0, n);
EVP_DecodeBlock(resp, chal, strlen((char *)(chal)));
HMAC_Init(&hmac, (const unsigned char *)pass, strlen(pass),
EVP_md5());
HMAC_Update(&hmac, resp, strlen((char *)(resp)));
HMAC_Final(&hmac, md, &mdlen);
xfree(chal);
xfree(resp);
for (i = 0; i < mdlen; i++)
snprintf((char *)(mdhex) + i * 2, mdlen * 2 - i * 2 + 1,
"%02x", md[i]);
mdhex[mdlen * 2] = '\0';
n = strlen(user) + 1 + strlen((char *)(mdhex)) + 1;
buf = (unsigned char *)xmalloc(n * sizeof(unsigned char));
memset(buf, 0, n);
snprintf((char *)(buf), n, "%s %s", user, mdhex);
n = (strlen((char *)(buf)) + 3) * 4 / 3 + 1;
out = (unsigned char *)xmalloc(n * sizeof(unsigned char));
memset(out, 0, n);
EVP_EncodeBlock(out, buf, strlen((char *)(buf)));
imap_continuation(ssn, (char *)(out), strlen((char *)(out)));
xfree(buf);
xfree(out);
} else
return -1;
return response_authenticate(ssn, t, NULL);
}
开发者ID:laszlo,项目名称:imapfilter,代码行数:61,代码来源:auth.c
示例12: EVP_EncodeUpdate
void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
const unsigned char *in, int inl)
{
int i,j;
unsigned int total=0;
*outl=0;
if (inl == 0) return;
OPENSSL_assert(ctx->length <= (int)sizeof(ctx->enc_data));
if ((ctx->num+inl) < ctx->length)
{
TINYCLR_SSL_MEMCPY(&(ctx->enc_data[ctx->num]),in,inl);
ctx->num+=inl;
return;
}
if (ctx->num != 0)
{
i=ctx->length-ctx->num;
TINYCLR_SSL_MEMCPY(&(ctx->enc_data[ctx->num]),in,i);
in+=i;
inl-=i;
j=EVP_EncodeBlock(out,ctx->enc_data,ctx->length);
ctx->num=0;
out+=j;
*(out++)='\n';
*out='\0';
total=j+1;
}
while (inl >= ctx->length)
{
j=EVP_EncodeBlock(out,in,ctx->length);
in+=ctx->length;
inl-=ctx->length;
out+=j;
*(out++)='\n';
*out='\0';
total+=j+1;
}
if (inl != 0)
TINYCLR_SSL_MEMCPY(&(ctx->enc_data[0]),in,inl);
ctx->num=inl;
*outl=total;
}
开发者ID:Wampamba-Nooh,项目名称:MicroFrameworkSDK-Mono,代码行数:43,代码来源:encode.cpp
示例13: EVP_EncodeFinal
void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, uint8_t *out, int *out_len) {
unsigned ret = 0;
if (ctx->num != 0) {
ret = EVP_EncodeBlock(out, ctx->enc_data, ctx->num);
out[ret++] = '\n';
out[ret] = '\0';
ctx->num = 0;
}
*out_len = ret;
}
开发者ID:Cyril2004,项目名称:proto-quic,代码行数:11,代码来源:base64.c
示例14: EVP_EncodeFinal
void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
{
unsigned int ret = 0;
if (ctx->num != 0) {
ret = EVP_EncodeBlock(out, ctx->enc_data, ctx->num);
out[ret++] = '\n';
out[ret] = '\0';
ctx->num = 0;
}
*outl = ret;
}
开发者ID:AndreV84,项目名称:openssl,代码行数:12,代码来源:encode.c
示例15: PEM_SealInit
int
PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk)
{
unsigned char key[EVP_MAX_KEY_LENGTH];
int ret = -1;
int i, j, max = 0;
char *s = NULL;
for (i = 0; i < npubk; i++) {
if (pubk[i]->type != EVP_PKEY_RSA) {
PEMerr(PEM_F_PEM_SEALINIT, PEM_R_PUBLIC_KEY_NO_RSA);
goto err;
}
j = RSA_size(pubk[i]->pkey.rsa);
if (j > max)
max = j;
}
s = (char *)reallocarray(NULL, max, 2);
if (s == NULL) {
PEMerr(PEM_F_PEM_SEALINIT, ERR_R_MALLOC_FAILURE);
goto err;
}
EVP_EncodeInit(&ctx->encode);
EVP_MD_CTX_init(&ctx->md);
if (!EVP_SignInit(&ctx->md, md_type))
goto err;
EVP_CIPHER_CTX_init(&ctx->cipher);
ret = EVP_SealInit(&ctx->cipher, type, ek, ekl, iv, pubk, npubk);
if (ret <= 0)
goto err;
/* base64 encode the keys */
for (i = 0; i < npubk; i++) {
j = EVP_EncodeBlock((unsigned char *)s, ek[i],
RSA_size(pubk[i]->pkey.rsa));
ekl[i] = j;
memcpy(ek[i], s, j + 1);
}
ret = npubk;
err:
if (s != NULL)
free(s);
OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH);
return (ret);
}
开发者ID:benwh4,项目名称:libressl,代码行数:51,代码来源:pem_seal.c
示例16: _SSL_get_obj_base64
static char *
_SSL_get_obj_base64(void *s, int type)
{
unsigned char *pt, *ppt;
unsigned char *t;
int len = 0;
int i;
switch (type) {
case 0:
len = i2d_PublicKey(s, NULL);
break;
case 1:
len = i2d_PrivateKey(s, NULL);
break;
case 2:
len = i2d_X509(s, NULL);
break;
}
if (len < 0)
return (NULL);
pt = ppt = mmalloc(len);
switch (type) {
case 0:
i2d_PublicKey(s, &pt);
break;
case 1:
i2d_PrivateKey(s, &pt);
break;
case 2:
i2d_X509(s, &pt);
break;
}
t = mmalloc(len * 2 + 1); /* + NULL */
if ((i = EVP_EncodeBlock(t, ppt, len)) == -1) {
fprintf(stderr, "_SSL_get_key_base64 :: EVP_EncodeBlock failed\n");
exit(1);
}
free (ppt);
return (t);
}
开发者ID:UIKit0,项目名称:picogui,代码行数:46,代码来源:ssl.c
示例17: NETSCAPE_SPKI_b64_encode
char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki)
{
unsigned char *der_spki, *p;
char *b64_str;
int der_len;
der_len = i2d_NETSCAPE_SPKI(spki, NULL);
der_spki = OPENSSL_malloc(der_len);
b64_str = OPENSSL_malloc(der_len * 2);
if(!der_spki || !b64_str) {
X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE);
return NULL;
}
p = der_spki;
i2d_NETSCAPE_SPKI(spki, &p);
EVP_EncodeBlock((unsigned char *)b64_str, der_spki, der_len);
OPENSSL_free(der_spki);
return b64_str;
}
开发者ID:houzhenggang,项目名称:mt7688_mips_ecos,代码行数:18,代码来源:x509spki.c
示例18: PEM_SealFinal
int
PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
unsigned char *out, int *outl, EVP_PKEY *priv)
{
unsigned char *s = NULL;
int ret = 0, j;
unsigned int i;
if (priv->type != EVP_PKEY_RSA) {
PEMerr(PEM_F_PEM_SEALFINAL, PEM_R_PUBLIC_KEY_NO_RSA);
goto err;
}
i = RSA_size(priv->pkey.rsa);
if (i < 100)
i = 100;
s = reallocarray(NULL, i, 2);
if (s == NULL) {
PEMerr(PEM_F_PEM_SEALFINAL, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!EVP_EncryptFinal_ex(&ctx->cipher, s, (int *)&i))
goto err;
EVP_EncodeUpdate(&ctx->encode, out, &j, s, i);
*outl = j;
out += j;
EVP_EncodeFinal(&ctx->encode, out, &j);
*outl += j;
if (!EVP_SignFinal(&ctx->md, s, &i, priv))
goto err;
*sigl = EVP_EncodeBlock(sig, s, i);
ret = 1;
err:
EVP_MD_CTX_cleanup(&ctx->md);
EVP_CIPHER_CTX_cleanup(&ctx->cipher);
if (s != NULL)
free(s);
return (ret);
}
开发者ID:benwh4,项目名称:libressl,代码行数:42,代码来源:pem_seal.c
示例19: raopd_base64_encode
utility_retcode_t raopd_base64_encode(char *dst,
size_t dstlen,
const uint8_t *src,
size_t srclen,
size_t *encoded_length)
{
utility_retcode_t ret = UTILITY_SUCCESS;
FUNC_ENTER;
DEBG("srclen: %d dstlen: %d\n", srclen, dstlen);
*encoded_length = EVP_EncodeBlock((uint8_t *)dst, src, srclen);
remove_base64_columnation(dst, encoded_length);
INFO("encoded_length: %d\n", *encoded_length);
FUNC_RETURN;
return ret;
}
开发者ID:dparnell,项目名称:raopd,代码行数:21,代码来源:encoding.c
示例20: mite_string_2_base64_block
int mite_string_2_base64_block(char *input,int input_len,char **base64)
{
int len = 0;
char *out = NULL;
out = malloc(((input_len/3+1)*4));
len = EVP_EncodeBlock(out,input,input_len);
*base64 = out;
return len;
/*
char *p = out+len-1;
int pad=0;
int i = 0;
for(i=0;i<4;i++)
{
if(*p=='=')
pad++;
p--;
}
*/
}
开发者ID:LiTianjue,项目名称:arm-vpn,代码行数:21,代码来源:mite_base64.c
注:本文中的EVP_EncodeBlock函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论