base64移植笔记(android)

本文介绍了Android源码中base64编码和解码的实现,主要关注于`base64.c`和`base64.h`文件,详细讲解了Base64编码和解码的函数实现过程,包括`base64_encode`和`base64_decode`等。代码遵循BSD许可证,并提供了示例用法,展示了如何在实际项目中使用这些函数进行Base64操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

base64源码位置:

android-11.0.0_r36

aosp/external/wpa_supplicant_8/src/utils/base64.c

aosp/external/wpa_supplicant_8/src/utils/base64.h

/*
 * Base64 encoding/decoding (RFC1341)
 * Copyright (c) 2005, Jouni Malinen <j@w1.fi>
 *
 * This software may be distributed under the terms of the BSD license.
 * See README for more details.
 */
#ifndef BASE64_H
#define BASE64_H
char * base64_encode(const void *src, size_t len, size_t *out_len);
unsigned char * base64_decode(const char *src, size_t len, size_t *out_len);
char * base64_url_encode(const void *src, size_t len, size_t *out_len);
unsigned char * base64_url_decode(const char *src, size_t len, size_t *out_len);
#endif /* BASE64_H */
/*
 * Base64 encoding/decoding (RFC1341)
 * Copyright (c) 2005-2019, Jouni Malinen <j@w1.fi>
 *
 * This software may be distributed under the terms of the BSD license.
 * See README for more details.
 */
#include "includes.h"
#include <stdint.h>
#include "os.h"
#include "base64.h"
static const char base64_table[65] =
	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char base64_url_table[65] =
	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
static char * base64_gen_encode(const unsigned char *src, size_t len,
				size_t *out_len, const char *table, int add_pad)
{
   
	char *out, *pos;
	const unsigned char *end, *in;
	size_t olen;
	int line_len;
	if (len >= SIZE_MAX / 4)
		return NULL;
	olen = len * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
	if (add_pad)
		olen += olen / 72; /* line feeds */
	olen++
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值