本文整理汇总了C++中EVP_EncodeBlock函数的典型用法代码示例。如果您正苦于以下问题:C++ EVP_EncodeBlock函数的具体用法?C++ EVP_EncodeBlock怎么用?C++ EVP_EncodeBlock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EVP_EncodeBlock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}