本文整理汇总了C++中BIO_get_mem_ptr函数的典型用法代码示例。如果您正苦于以下问题:C++ BIO_get_mem_ptr函数的具体用法?C++ BIO_get_mem_ptr怎么用?C++ BIO_get_mem_ptr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BIO_get_mem_ptr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: flatten_X509
struct X509_flat *
flatten_X509(X509 *x)
{
struct X509_flat *out = NULL;
int ret;
BUF_MEM *bptr = NULL;
BIO *mem = NULL;
if (x == NULL) {
return NULL;
}
mem = BIO_new(BIO_s_mem());
if (mem == NULL) {
return NULL;
}
ret = PEM_write_bio_X509(mem, x);
if (ret == 0) {
BIO_free(mem);
return NULL;
}
out = new_X509_flat();
if (out == NULL) {
BIO_free(mem);
return NULL;
}
BIO_get_mem_ptr(mem, &bptr);
assert(BIO_set_close(mem, BIO_NOCLOSE) == 1);
BIO_free(mem);
out->len = bptr->length;
if (bptr->length != 0
&& (size_t) bptr->length <= SIZE_MAX/sizeof(*(out->data))) {
out->data = malloc(bptr->length*sizeof(*(out->data)));
}
if (out->data == NULL) {
BUF_MEM_free(bptr);
return NULL;
}
memcpy(out->data, bptr->data, bptr->length);
BUF_MEM_free(bptr);
return out;
}
开发者ID:Crashdowns,项目名称:phantom,代码行数:43,代码来源:x509_flat.c
示例2: encode_base64
char* encode_base64(unsigned char* data, size_t length) {
BIO *bmem, *b64;
BUF_MEM *bufmem;
b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
BIO_write(b64, data, length);
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bufmem);
BIO_set_close(b64, BIO_NOCLOSE);
BIO_free_all(b64);
return bufmem->data;
}
开发者ID:sfelton,项目名称:matasano,代码行数:19,代码来源:decode_encode.c
示例3: BIO_new
int utils::Base64Encode(const unsigned char* buffer, size_t length, char** b64text) { //Encodes a binary safe base 64 string
BIO *bio, *b64;
BUF_MEM *bufferPtr;
b64 = BIO_new(BIO_f_base64());
bio = BIO_new(BIO_s_mem());
bio = BIO_push(b64, bio);
BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); //Ignore newlines - write everything in one line
BIO_write(bio, buffer, length);
BIO_flush(bio);
BIO_get_mem_ptr(bio, &bufferPtr);
BIO_set_close(bio, BIO_NOCLOSE);
BIO_free_all(bio);
*b64text=(*bufferPtr).data;
return (0); //success
}
开发者ID:athongintel,项目名称:irm5-ec_crypto,代码行数:19,代码来源:utils.cpp
示例4: LUA_FUNCTION
static LUA_FUNCTION(openssl_pkcs7_decrypt)
{
PKCS7 *p7 = CHECK_OBJECT(1, PKCS7, "openssl.pkcs7");
X509 *cert = CHECK_OBJECT(2, X509, "openssl.x509");
EVP_PKEY *key = CHECK_OBJECT(3, EVP_PKEY, "openssl.evp_pkey");
long flags = luaL_optint(L, 4, 0);
BIO *out = BIO_new(BIO_s_mem());
if (PKCS7_decrypt(p7, key, cert, out, flags))
{
BUF_MEM* mem;
BIO_get_mem_ptr(out, &mem);
lua_pushlstring(L, mem->data, mem->length);
}
else
lua_pushnil(L);
BIO_free(out);
return 1;
}
开发者ID:Shaddy1884,项目名称:lua-openssl,代码行数:19,代码来源:pkcs7.c
示例5: b64_encode
//------------------------------------------------------------------------------
// helper function to encode a vector of bytes to a base64 string:
static std::string b64_encode(const std::vector<unsigned char>& data)
{
BIO* b64 = BIO_new(BIO_f_base64());
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
BIO* bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
BIO_write(b64, data.data(), data.size());
BIO_flush(b64);
BUF_MEM* bptr = NULL;
BIO_get_mem_ptr(b64, &bptr);
std::string output(bptr->data, bptr->length);
BIO_free_all(b64);
return output;
}
开发者ID:CrazyCaptian,项目名称:Test,代码行数:21,代码来源:kclient.cpp
示例6: BIO_new
char *base64(const unsigned char *input, int length)
{
BIO *bmem, *b64;
BUF_MEM *bptr;
b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
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);
buff[bptr->length-1] = 0;
BIO_free_all(b64);
return buff;
}
开发者ID:katmagic,项目名称:perspectives-notary-server,代码行数:19,代码来源:notary_crypto.c
示例7: encode
passwand_error_t encode(const uint8_t *s, size_t len, char **e) {
assert(s != NULL);
assert(e != NULL);
if (len > (size_t)INT_MAX)
return PW_OVERFLOW;
/* Create a base64 filter. */
BIO *b64 __attribute__((cleanup(autobiofree))) = BIO_new(BIO_f_base64());
if (b64 == NULL)
return PW_NO_MEM;
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
/* Create an in-memory sink to encode data into. */
BIO *out = BIO_new(BIO_s_mem());
if (out == NULL)
return PW_NO_MEM;
BIO *pipe __attribute__((cleanup(autobiofree))) = BIO_push(b64, out);
b64 = NULL;
/* Encode the data. */
if (BIO_write(pipe, s, len) != (int)len)
return PW_IO;
BIO_flush(pipe);
/* Extract it into a string. */
BUF_MEM *bptr;
BIO_get_mem_ptr(out, &bptr);
if (SIZE_MAX - 1 < bptr->length)
return PW_OVERFLOW;
*e = malloc(bptr->length + 1);
if (*e == NULL)
return PW_NO_MEM;
memcpy(*e, bptr->data, bptr->length);
(*e)[bptr->length] = '\0';
return PW_OK;
}
开发者ID:Smattr,项目名称:passwand,代码行数:42,代码来源:encoding.c
示例8: base_64_encode
//Function to use openssl to do BASE64 encoding
static bool base_64_encode(const uint8_t *in_buf, uint32_t in_size, uint8_t *out_buf, uint32_t *out_size)
{
BIO* bioMem = NULL;
bool ret = false;
BIO *bio64 = NULL;
BIO_METHOD *bm = BIO_f_base64();
if(bm == NULL)
goto ret_point;
bio64 = BIO_new(bm);
if(bio64 == NULL)
goto ret_point;
BIO_set_flags(bio64, BIO_FLAGS_BASE64_NO_NL);
bm = BIO_s_mem();
if(bm == NULL)
goto ret_point;
bioMem = BIO_new(bm);
if(bioMem == NULL)
goto ret_point;
(void)BIO_push(bio64, bioMem);
if(BIO_write(bio64, in_buf, in_size) != (int)in_size){
goto ret_point;
}
(void)BIO_flush(bio64);
BUF_MEM *bptr;
BIO_get_mem_ptr(bio64, &bptr);
if(bptr==NULL){
goto ret_point;
}
if(*out_size < bptr->length){
goto ret_point;
}
if(memcpy_s(out_buf, *out_size,bptr->data, bptr->length)!=0)
goto ret_point;
*out_size = static_cast<uint32_t>(bptr->length);
ret = true;
ret_point:
BIO_free_all(bio64);//we need not free bioMem too because the free_all has free it.
return ret;
}
开发者ID:0-T-0,项目名称:linux-sgx,代码行数:43,代码来源:aesm_encode.cpp
示例9: BIO_new
// ============================================================================
std::string Crypto::base64(const std::vector<uint8_t>& input)
{
BIO *bmem, *b64;
BUF_MEM* bptr;
std::string result;
b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
BIO_set_flags(bmem, BIO_FLAGS_BASE64_NO_NL);
BIO_write(b64, input.data(), (int)input.size());
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);
result.resize(bptr->length - 1);
memcpy(&result[0], bptr->data, bptr->length - 1);
BIO_free_all(b64);
return result;
} // base64
开发者ID:qwertychouskie,项目名称:stk-code,代码行数:21,代码来源:crypto_openssl.cpp
示例10: base64_encode
static int base64_encode(char *str,int str_len,char *encode,int encode_len)
{
BIO *bmem,*b64;
BUF_MEM *bptr;
b64=BIO_new(BIO_f_base64());
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);
if(bptr->length>encode_len){
oss_log_write("encode_len too small\n");
return -1;
}
encode_len=bptr->length;
memcpy(encode,bptr->data,bptr->length);
// write(1,encode,bptr->length);
BIO_free_all(b64);
return encode_len;
}
开发者ID:xuanya4202,项目名称:aliyun_oss,代码行数:20,代码来源:oss_http_request.c
示例11: encodeBase64
gchar* encodeBase64(gchar *input, gint length) {
BIO *b64 = BIO_new(BIO_f_base64());
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
BIO *bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
BIO_write(b64, input, length);
BIO_flush(b64);
BUF_MEM *buffer;
BIO_get_mem_ptr(b64, &buffer);
gchar *data = g_malloc(buffer->length);
memcpy(data, buffer->data, buffer->length - 1);
data[buffer->length - 1] = 0;
BIO_free_all(b64);
return data;
}
开发者ID:houzhenggang,项目名称:openwrt-ar9331,代码行数:20,代码来源:ssl.c
示例12: BIO_new
char *Base64::encode(const char *input, int size)
{
BIO *bmem, *b64;
BUF_MEM *bptr;
b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
BIO_write(b64, input, size);
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);
char *buff = (char *)Memory::Alloc(bptr->length);
memcpy(buff, bptr->data, bptr->length-1);
buff[bptr->length-1] = 0;
BIO_free_all(b64);
return buff;
}
开发者ID:WizKid,项目名称:FriBID-windows,代码行数:20,代码来源:base64.cpp
示例13: BIO_new
static char *base64(char *str, size_t *len) {
BIO *b64, *bmem;
BUF_MEM *bptr;
b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
BIO_write(b64, str, *len);
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);
char *buf = malloc(bptr->length-1);
memcpy(buf, bptr->data, bptr->length-1);
*len = bptr->length-1;
BIO_free_all(b64);
return buf;
}
开发者ID:20tab,项目名称:blastbeat,代码行数:20,代码来源:websocket.c
示例14: SSL_write
std::streamsize Connection::write(const char* buf, std::size_t n)
{
std::streambuf* sb = _ios->rdbuf();
if( ! sb)
return 0;
std::streamsize written = SSL_write(_ssl, buf, n);
log_debug("encrypted " << written << " bytes");
BUF_MEM* bm = 0;
BIO_get_mem_ptr(_out, &bm);
if(bm->length > 0)
{
sb->sputn(bm->data, bm->length);
log_debug("wrote " << bm->length << " bytes to output");
bm->length = 0;
}
return written;
}
开发者ID:3Nigma,项目名称:frayon,代码行数:20,代码来源:Connection.cpp
示例15: codec_base64_encode
/**
* BASE64编码
*
* LUA示例:
* local codec = require('codec')
* local bs = [[...]] --源内容
* local result = codec.base64_encode(bs)
*/
static int codec_base64_encode(lua_State *L)
{
size_t len;
const char *bs = luaL_checklstring(L, 1, &len);
BIO *b64 = BIO_new(BIO_f_base64());
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
BIO *bio = BIO_new(BIO_s_mem());
bio = BIO_push(b64, bio);
BIO_write(bio, bs, len);
BIO_flush(bio);
BUF_MEM *p;
BIO_get_mem_ptr(bio, &p);
int n = p->length;
char dst[n];
memcpy(dst, p->data, n);
BIO_free_all(bio);
lua_pushlstring(L, dst, n);
return 1;
}
开发者ID:mashijie,项目名称:lua-codec,代码行数:28,代码来源:codec.c
示例16: openssl_ssl_session_export
static int openssl_ssl_session_export(lua_State*L)
{
SSL_SESSION* session = CHECK_OBJECT(1, SSL_SESSION, "openssl.ssl_session");
int pem = lua_isnoneornil(L, 2) ? 1 : auxiliar_checkboolean(L, 2);
BIO* bio = BIO_new(BIO_s_mem());
BUF_MEM *bio_buf;
if (pem)
{
PEM_write_bio_SSL_SESSION(bio, session);
}
else
{
i2d_SSL_SESSION_bio(bio, session);
}
BIO_get_mem_ptr(bio, &bio_buf);
lua_pushlstring(L, bio_buf->data, bio_buf->length);
BIO_free(bio);
return 1;
}
开发者ID:witchu,项目名称:lua-openssl,代码行数:20,代码来源:ssl.c
示例17: crypto_pk_write_key_to_string_impl
/** Helper function to implement crypto_pk_write_*_key_to_string. */
int crypto_pk_write_key_to_string_impl(crypto_pk_t *env, char **dest,
size_t *len, int is_public)
{
BUF_MEM *buf;
BIO *b;
int r;
// assert(env);
// assert(env->key);
// assert(dest);
b = BIO_new(BIO_s_mem()); /* Create a memory BIO */
if (!b)
return -1;
/* Now you can treat b as if it were a file. Just use the
* PEM_*_bio_* functions instead of the non-bio variants.
*/
if (is_public)
r = PEM_write_bio_RSAPublicKey(b, env->key);
else
r = PEM_write_bio_RSAPrivateKey(b, env->key, NULL,NULL,0,NULL,NULL);
if (!r) {
err(1, "writing RSA key to string");
BIO_free(b);
return -1;
}
BIO_get_mem_ptr(b, &buf);
(void)BIO_set_close(b, BIO_NOCLOSE); /* so BIO_free doesn't free buf */
BIO_free(b);
*dest = sgx_malloc(buf->length+1);
sgx_memcpy(*dest, buf->data, buf->length);
(*dest)[buf->length] = 0; /* nul terminate it */
*len = buf->length;
BUF_MEM_free(buf);
return 0;
}
开发者ID:johnjohnsp1,项目名称:opensgx,代码行数:42,代码来源:sgx-tor.c
示例18: BIO_new
char *bin2Base64PlusSlashEqualsMultiLine(const unsigned char *input, int length)
{
// from http://www.ioncannon.net/programming/34/howto-base64-encode-with-cc-and-openssl/
BIO *bmem, *b64;
BUF_MEM *bptr;
b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
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);
buff[bptr->length-1] = 0;
BIO_free_all(b64);
return buff;
}
开发者ID:2i3r,项目名称:PBKDF2-GCC-OpenSSL-library,代码行数:21,代码来源:pbkdf2_openssl.c
示例19: BIO_new
/**
dsa_get_ppk
Returns a dynamically allocated string like the following:
-----BEGIN PUBLIC KEY-----
...Some, uh, public key...
-----END PUBLIC KEY-----
or NULL on error. Note that the pointer is dynamically allocated.
*/
char *dsa_get_ppk()
{
BIO *fsu = BIO_new(BIO_s_mem());
BUF_MEM *buf;
char *realbuf = NULL;
if(fsu == NULL)
return NULL;
PEM_write_bio_DSA_PUBKEY(fsu, probe);
BIO_flush(fsu);
BIO_get_mem_ptr(fsu, &buf);
if((realbuf = malloc(53 + buf->length)) != NULL) {
memcpy(realbuf, buf->data, buf->length);
realbuf[buf->length] = '\0';
}
BIO_free(fsu);
return realbuf;
}
开发者ID:pete,项目名称:freenote-probe,代码行数:31,代码来源:pdsa.c
示例20: BIO_new
char* CryptoHandler::base64encode(const unsigned char *input, const 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, input, length);
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);
char *buff = (char *)malloc(bptr->length);
memcpy(buff, bptr->data, bptr->length-1);
buff[bptr->length-1] = 0;
BIO_free_all(b64);
return buff;
}
开发者ID:GYGit,项目名称:ffead-cpp,代码行数:21,代码来源:CryptoHandler.cpp
注:本文中的BIO_get_mem_ptr函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论