当前位置: 首页>>代码示例>>C++>>正文


C++ BIO_f_base64函数代码示例

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


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


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