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

C++ BIO_f_base64函数代码示例

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

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



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

示例1: main

int
main(int argc, char** argv)
{
    // get data to encrypt.  
    //
    if (argc != 3) {
        printf("Usage: %s <base64 enc key> <data to encryt>\n",
                argv[0]);
        return 0;
    }

    // base64 decode key
    //
    BIO *mbio = BIO_new_mem_buf(argv[1], strlen(argv[1]));
    BIO *b64bio = BIO_new(BIO_f_base64());
    BIO_set_flags(b64bio, BIO_FLAGS_BASE64_NO_NL);
    BIO *bio = BIO_push(b64bio, mbio);

    char key[256];
    size_t keylen = 0;
    keylen = BIO_read(bio, key, sizeof(key));

    BIO_free(mbio);
    BIO_free(b64bio);

    // encrypt the data
    //
    char out[256];
    int outlen = 0;
    EVP_CIPHER_CTX ctx;
    EVP_EncryptInit(&ctx, EVP_aes_256_ecb(), key, NULL);
    EVP_EncryptUpdate(&ctx, out, &outlen, argv[2], strlen(argv[2]));
    EVP_EncryptFinal(&ctx, out, &outlen);
    EVP_CIPHER_CTX_cleanup(&ctx);

    // base64 encode encrypted data
    //
    mbio = BIO_new(BIO_s_mem());
    b64bio = BIO_new(BIO_f_base64());
    BIO_set_flags(b64bio, BIO_FLAGS_BASE64_NO_NL);
    bio = BIO_push(b64bio, mbio);

    BIO_write(bio, out, outlen);
    BIO_flush(bio);

    char* data = NULL;
    size_t datalen = 0;
    datalen = BIO_get_mem_data(mbio, &data);
    data[datalen] = '\0';

    printf("encrypted data: [%s]\n", data);

    BIO_free(mbio);
    BIO_free(b64bio);

    return 0;
}
开发者ID:pp7462-git,项目名称:sandbox,代码行数:57,代码来源:aesencrypttest.c


示例2: BIO_new

char *base64_enc(const char *str, int len)
{
	BIO *bio, *b64;
	BUF_MEM *bptr;
	char *buf;
	int ret;

	b64 = BIO_new(BIO_f_base64());
	bio = BIO_new(BIO_s_mem());
	b64 = BIO_push(b64, bio);

	ret = BIO_write(b64, str, len);
	if (ret <= 0) {
		buf = NULL;
		goto err;
	}
	BIO_flush(b64);
	BIO_get_mem_ptr(b64, &bptr);

	buf = malloc(bptr->length);
	if (buf) {
		memcpy(buf, bptr->data, bptr->length-1);
		buf[bptr->length - 1] = 0;
	}

err:
	BIO_free_all(b64);

	return buf;
}
开发者ID:ionutradu,项目名称:mailfilter,代码行数:30,代码来源:base64.c


示例3: s3_base64_encode

gchar*
s3_base64_encode(const GByteArray *to_enc) {
    BIO *bio_b64 = NULL, *bio_buff = NULL;
    long bio_b64_len;
    char *bio_b64_data = NULL, *ret = NULL;
    if (!to_enc) return NULL;

    /* Initialize base64 encoding filter */
    bio_b64 = BIO_new(BIO_f_base64());
    g_assert(bio_b64);
    BIO_set_flags(bio_b64, BIO_FLAGS_BASE64_NO_NL);

    /* Initialize memory buffer for the base64 encoding */
    bio_buff = BIO_new(BIO_s_mem());
    g_assert(bio_buff);
    bio_buff = BIO_push(bio_b64, bio_buff);

    /* Write the MD5 hash into the buffer to encode it in base64 */
    BIO_write(bio_buff, to_enc->data, to_enc->len);
    /* BIO_flush is a macro and GCC 4.1.2 complains without this cast*/
    (void) BIO_flush(bio_buff);

    /* Pull out the base64 encoding of the MD5 hash */
    bio_b64_len = BIO_get_mem_data(bio_buff, &bio_b64_data);
    g_assert(bio_b64_data);
    ret = g_strndup(bio_b64_data, bio_b64_len);

    /* If bio_b64 is freed separately, freeing bio_buff will
     * invalidly free memory and potentially segfault.
     */
    BIO_free_all(bio_buff);
    return ret;
}
开发者ID:TonyChiang,项目名称:amanda,代码行数:33,代码来源:s3-util.c


示例4: BIO_new

	char *base64(const unsigned char *input, int length)
	{
		BIO *bmem, *b64;
		BUF_MEM *bptr;

		b64 = BIO_new(BIO_f_base64());
		BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL);

		bmem = BIO_new(BIO_s_mem());
		b64 = BIO_push(b64, bmem);
		BIO_write(b64, magic, sizeof(magic)-1);
		BIO_write(b64, (char*)salt, sizeof(salt));

		BIO_write(b64, input, length);
		BIO_flush(b64);
		BIO_get_mem_ptr(b64, &bptr);

		char *buff = (char *)malloc(bptr->length);
//		memcpy(buff, bptr->data, bptr->length-1);

		int chars = 0;
		for (unsigned int i = 0; i < bptr->length-1; i++) {
			if (bptr->data[i] == '+') { buff[chars] = '-'; chars++;}
			else if (bptr->data[i] == '/') { buff[chars] = '_'; chars++; }
			else if (bptr->data[i] != '=') { buff[chars] = bptr->data[i]; chars++; }
		}

		buff[chars] = 0;
		
		BIO_free_all(b64);


		return buff;
	}
开发者ID:asturel,项目名称:znc_modules,代码行数:34,代码来源:notifier.cpp


示例5: we

/**
	b64decode
	Decodes a base64-encoded message.  You provide an encoded message,
	and a pointer to somewhere we (the editorial we) can store the length 
	of the decoded message.  A dynamically allocated pointer is returned.
*/
char *b64decode(char *encoded, size_t *newlen)
{
        BIO     *b64, *bmem;
        char    *decoded = NULL;

	if(encoded == NULL) {
		print_loc(); io_debug("NULL data passed!  Bad coder!  Bad!\n");
		return NULL;
	}

	safe_malloc(decoded,*newlen);
        b64 = BIO_new(BIO_f_base64());
        bmem = BIO_new_mem_buf(encoded, -1);
	if(bmem == NULL || b64 == NULL) {
		print_loc(); io_debug("Calls to libssl failed!\n");
		abort();  //I don't think this will ever happen.
	}

        bmem = BIO_push(b64, bmem);
        *newlen = BIO_read(bmem, decoded, *newlen);
	BIO_free_all(bmem);

	decoded[*newlen] = '\0';


	return decoded;
}
开发者ID:pete,项目名称:freenote-probe,代码行数:33,代码来源:base64.c


示例6: decodeBase64

char* decodeBase64(unsigned char *input, size_t length, size_t *out_length) {
  BIO *b64, *bmem;
  size_t decodedLen;

  char *buffer = (char*)NFCD_MALLOC(length+1);
  if (buffer == NULL) {
    return NULL;
  }
  memset(buffer, 0, length);

  b64 = BIO_new(BIO_f_base64());
  if (b64 == NULL) {
    return NULL;
  }
  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
  bmem = BIO_new_mem_buf(input, length);
  bmem = BIO_push(b64, bmem);

  decodedLen = BIO_read(bmem, buffer, length);
  buffer[decodedLen] = 0;
  *out_length = decodedLen;

  BIO_free_all(bmem);
  return buffer;
}
开发者ID:svic,项目名称:b2g-nfcd,代码行数:25,代码来源:nfcd_util.cpp


示例7: base64Decode

static Buffer::Ptr base64Decode(T t) {
    if (!t) return Buffer::null();
    if (!t->length()) return Buffer::create();

    std::string src = t->toStdString();
    Size len = src.length();
    if (len != t->length()) return Buffer::null();

    BIO* bio = BIO_new(BIO_f_base64());
    BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
    BIO* bioMem = BIO_new_mem_buf(const_cast<char*>(src.c_str()), len);
    bio = BIO_push(bio, bioMem);

    char* dst = new char[len + 1];
    int readLen = BIO_read(bio, dst, len);
    Buffer::Ptr decoded;
    if (readLen > 0) {
        decoded = Buffer::create(dst, readLen);
    } else {
        decoded = Buffer::null();
    }
    BIO_free_all(bio);
    delete[] dst;
    return decoded;
}
开发者ID:LittoCats,项目名称:libnode,代码行数:25,代码来源:util.cpp


示例8: write_b64

int write_b64( const char *filename, unsigned char *out, int len )
{
    int count;
    BIO *b64, *file;

    /* Create a buffered file BIO for writing */
    file = BIO_new_file (filename, "w");
    if (!file) {
        /* FIXME - log an error */
        return -1;
    }

    /* Create a base64 encoding filter BIO */
    b64 = BIO_new (BIO_f_base64 ());
    assert( b64 != NULL );
    if( b64 == NULL ) {
        /* FIXME - log an error */
        return -1;
    }

    /* Assemble the BIO chain to be in the order b64-file */
    BIO_push (b64, file );

    count = write_to_BIO( b64, out, len );
    assert( count == len );

    BIO_free_all( b64 );

    /* success */
    return count;
}
开发者ID:linuxlizard,项目名称:snmptree,代码行数:31,代码来源:AgentList.cpp


示例9: clevis_buf_encode

json_t *
clevis_buf_encode(const clevis_buf_t *buf)
{
  json_t *out = NULL;
  BIO *mem = NULL;
  BIO *b64 = NULL;
  char *c = NULL;
  int r = 0;

  mem = BIO_new(BIO_s_mem());
  if (!mem)
    goto egress;

  b64 = BIO_new(BIO_f_base64());
  if (!b64)
    goto egress;

  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
  if (!BIO_push(b64, mem))
    goto egress;

  r = BIO_write(b64, buf->buf, buf->len);
  if (r != (int) buf->len)
    goto egress;

  BIO_flush(b64);

  r = BIO_get_mem_data(mem, &c);
  out = json_stringn(c, r);

egress:
  BIO_free(b64);
  BIO_free(mem);
  return out;
}
开发者ID:ep69,项目名称:clevis,代码行数:35,代码来源:buf.c


示例10: base64Encode

static int base64Encode(char* output, const unsigned char* data, size_t length)
{
    BIO* base64 = BIO_new(BIO_f_base64());
    if (base64 == NULL) {
        return -1;
    }
    BIO_set_flags(base64, BIO_FLAGS_BASE64_NO_NL);
    BIO* memory = BIO_new(BIO_s_mem());
    if (memory == NULL) {
        BIO_free_all(base64);
        return -1;
    }
    BIO* bio = BIO_push(base64, memory);
    BIO_write(bio, data, length);
    if (BIO_flush(bio) == -1) {
        return -1;
    }
    const char* p;
    size_t n = BIO_get_mem_data(memory, &p);
    int i;
    for (i = 0; i < n; ++i) {
        if (*(p+i) == '+') {
            *(output+i) = '-';
        } else if (*(p+i) == '/') {
            *(output+i) = '_';
        } else if (*(p+i) == '=') {
            break;
        } else {
            *(output+i) = *(p+i);
        }
    }

    BIO_free_all(bio);
    return n;
}
开发者ID:houzhenggang,项目名称:mt7688_mips_ecos,代码行数:35,代码来源:system_ecos.c


示例11: unbase64

static size_t unbase64(const char *bytes, char **unbase64)
{
	size_t len;
	BIO *memory, *b64;
	char *buffer;

	len = strlen(bytes);
	if (!len)
		goto error;
	b64 = BIO_new(BIO_f_base64());
	memory = BIO_new_mem_buf((char *)bytes, len);
	if (!b64 || !memory)
		goto error;
	b64 = BIO_push(b64, memory);
	if (!b64)
		goto error;
	BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
	buffer = xcalloc(len + 1, 1);
	len = BIO_read(b64, buffer, len);
	if ((int)len <= 0)
		goto error;
	buffer[len] = '\0';

	BIO_free_all(b64);
	*unbase64 = buffer;
	return len;

error:
	die("Could not unbase64 the given bytes.");
}
开发者ID:TonyAbell,项目名称:lastpass-cli,代码行数:30,代码来源:cipher.c


示例12: BIO_new

static char *base64(const char *bytes, size_t len)
{
	BIO *memory, *b64;
	BUF_MEM *buffer;
	char *output;

	b64 = BIO_new(BIO_f_base64());
	BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
	memory = BIO_new(BIO_s_mem());
	if (!b64 || !memory)
		goto error;
	b64 = BIO_push(b64, memory);
	if (!b64)
		goto error;
	if (BIO_write(b64, bytes, len) < 0 || BIO_flush(b64) < 0)
		goto error;

	BIO_get_mem_ptr(b64, &buffer);
	output = xmalloc(buffer->length + 1);
	memcpy(output, buffer->data, buffer->length);
	output[buffer->length] = '\0';

	BIO_free_all(b64);
	return output;

error:
	die("Could not base64 the given bytes.");
}
开发者ID:TonyAbell,项目名称:lastpass-cli,代码行数:28,代码来源:cipher.c


示例13: base64_encode

/*
 * des - base64编码,将二进制字符与64个可打印字符进行对应转化。 2^6 = 64,6bits对应一个字符,三个字节对应四个可见字符
 * param - str : 需编码的数据
 *		   str_len : str的长度
 *		   encode : 编码后数据存储
 *		   encode_len : encode缓冲区的长度,要求大小需大于str_len,建议为(str_len/3) * 4 + 8
 * ret - success : 编码后数据实际长度
 * 		 fail : -1
 */
int base64_encode(char *str,int str_len,char *encode, u_int encode_len)
{
	BIO *bmem,*b64;
	BUF_MEM *bptr;

	b64=BIO_new(BIO_f_base64());
	BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
	bmem=BIO_new(BIO_s_mem());
	b64=BIO_push(b64, bmem);

	BIO_write(b64, str, str_len); //encode
	BIO_flush(b64);
	BIO_get_mem_ptr(b64,&bptr);

//	printf("%d\n", bptr->length);

	if(bptr->length > encode_len){
		 printf("encode_len too small\n");
		 return -1; 
	}   

	encode_len=bptr->length;
	memcpy(encode,bptr->data,bptr->length);
	encode[bptr->length] = '\0';
	BIO_free_all(b64);

	return encode_len;
}
开发者ID:misslio,项目名称:lctools,代码行数:37,代码来源:aes_base64.c


示例14: decodeBase64

gchar* decodeBase64(gchar *data, gint length, gint *actualLength) {
    gchar *input = data;
    gint correctedLength = getCorrectedEncodeSize(length);
    if(length != correctedLength) {
        input = g_malloc(correctedLength * sizeof(gchar));
        memset(input, 0, correctedLength);
        memcpy(input, data, length);
        memset(input + length, '=', correctedLength - length);
    }
    gchar *buffer = g_malloc(correctedLength);
    memset(buffer, 0, correctedLength);

    BIO *b64 = BIO_new(BIO_f_base64());
    BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);

    BIO *bmem = BIO_new_mem_buf(input, correctedLength);
    BIO_set_flags(bmem, BIO_FLAGS_BASE64_NO_NL);
    bmem = BIO_push(b64, bmem);

    BIO_set_flags(bmem, BIO_FLAGS_BASE64_NO_NL);

    *actualLength = BIO_read(bmem, buffer, correctedLength);

    BIO_free_all(bmem);

    if(length != correctedLength) {
        g_free(input);
    }
    return buffer;
}
开发者ID:houzhenggang,项目名称:openwrt-ar9331,代码行数:30,代码来源:ssl.c


示例15: memset

char *base64_dec(char *str, int len, int *result_len)
{
	BIO *bio, *b64;
	char *buf;
	int ret;

	if (!(buf = malloc(len)))
		return NULL;

	memset(buf, 0, len);

	b64 = BIO_new(BIO_f_base64());
	bio = BIO_new_mem_buf(str, len);
	bio = BIO_push(b64, bio);

	ret = BIO_read(bio, buf, len);
	if (ret <= 0) {
		free(buf);
		buf = NULL;
	}
	BIO_free_all(bio);

	if (result_len)
		*result_len = ret;

	return buf;
}
开发者ID:ionutradu,项目名称:mailfilter,代码行数:27,代码来源:base64.c


示例16: malloc

/* caller must free the returned string */
char *base64_dec(unsigned char *in, int size)
{
  BIO *bio64, *biomem;
  char *buf=NULL;

  buf = malloc(sizeof(char) * size);
  bzero(buf, size);

  if ((bio64 = BIO_new(BIO_f_base64())) == NULL) {
    logprintfl(EUCAERROR, "BIO_new(BIO_f_base64()) failed\n");
  } else {
    BIO_set_flags (bio64, BIO_FLAGS_BASE64_NO_NL); /* no long-line wrapping */

    if ((biomem = BIO_new_mem_buf(in, size)) == NULL) {
      logprintfl(EUCAERROR, "BIO_new_mem_buf() failed\n");
    } else {
      biomem = BIO_push(bio64, biomem);

      if ((BIO_read(biomem, buf, size)) <= 0) {
        logprintfl(EUCAERROR, "BIO_read() read failed\n");
      }
      //      BIO_free_all(biomem);
    }
    BIO_free_all(bio64);
  }

  return buf;
}
开发者ID:chrkl,项目名称:eucalyptus,代码行数:29,代码来源:euca_auth.c


示例17: alloc_cipher_BIOs

int alloc_cipher_BIOs( BIO **buffer, BIO **b64, BIO **cipher )
{
    *buffer = *b64 = *cipher = NULL; 

    /* Create a buffering filter BIO to buffer writes to the file */
    *buffer = BIO_new (BIO_f_buffer ());
    if( buffer == NULL ) {
        return -1;
    }

    /* Create a base64 encoding filter BIO */
    *b64 = BIO_new (BIO_f_base64 ());
    if( *b64 == NULL ) {
        BIO_free( *buffer );
        *buffer = NULL;
        return -1;
    }
    
    *cipher = BIO_new (BIO_f_cipher ());
    if( *cipher == NULL ) {
        BIO_free( *buffer );
        BIO_free( *b64 );
        *buffer = *b64 = NULL;
        return -1;
    }

    /* success */
    return 0;
}
开发者ID:linuxlizard,项目名称:snmptree,代码行数:29,代码来源:AgentList.cpp


示例18: BIO_new

char *EstEID_base64Encode(const char *input, int length) {
	BIO *memBio;
	BIO *b64Bio;
	char *b;
	int len;
	char *result;

	LOG_LOCATION;

	memBio = BIO_new(BIO_s_mem());
	b64Bio = BIO_new(BIO_f_base64());
	b64Bio = BIO_push(b64Bio, memBio);

	BIO_write(b64Bio, input, length);
	(void)BIO_flush(b64Bio);


	len = BIO_get_mem_data(memBio, &b);
	result = (char *)malloc(len + 1);
	strncpy(result, b, len);
	result[len] = 0;
	BIO_free_all(b64Bio);
	while (result[--len] == '\n') result[len] = 0;
	return result;
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:25,代码来源:esteid_sign.c


示例19: read_b64

int read_b64( const char *filename, unsigned char *out, int len )
{
    int count;
    BIO *b64, *buffer, *file;

    /* Create a buffered file BIO for reading */
    file = BIO_new_file (filename, "r");
    if (!file) {
        /* FIXME - log an error */
        return -1;
    }

    /* Create a base64 encoding filter BIO */
    b64 = BIO_new (BIO_f_base64 ());
    if( b64 == NULL ) {
        /* FIXME - log an error */
        return -1;
    }

    buffer = BIO_new (BIO_f_buffer ());

    /* Assemble the BIO chain to be in the order b64-file */
    BIO_push (b64, buffer );
    BIO_push( buffer, file );

    /* load the data */
    count = read_from_BIO( b64, out, len );
    assert( count == len );

    BIO_free_all( b64 );

    /* success */
    return count;
}
开发者ID:linuxlizard,项目名称:snmptree,代码行数:34,代码来源:AgentList.cpp


示例20: BIO_new

/*
 * Base64 encode a buffer passed in. Return a talloc allocated string.
 */
static char *base64_enc(void *ctx, 
			const char *buf,
			size_t size)
{
	BIO *b64_filter = BIO_new(BIO_f_base64());
	BIO *mem_ssink  = BIO_new(BIO_s_mem());
	BUF_MEM *bio_mem = NULL;
	int ret = 0;
	char *ret_str;

	b64_filter = BIO_push(b64_filter, mem_ssink);
	ret = BIO_write(b64_filter, buf, size);
	if (ret < 0 || ret != size) {
		DEBUG(0, ("Unable to write all data to b64_filter: %s\n",
			strerror(errno)));
	}
	ret = BIO_flush(b64_filter);

	BIO_get_mem_ptr(b64_filter, &bio_mem);

	/* This should append a terminating null to turn it into a string */
	ret_str = talloc_strndup(ctx, bio_mem->data, bio_mem->length);

	BIO_free_all(b64_filter);

	return ret_str;
}
开发者ID:RichardSharpe,项目名称:Amazon-S3-VFS,代码行数:30,代码来源:vfs_amazon_s3.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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