base64解码
网络传输经常用base64编码的数据,因此我们需要将其解码成正常字符集合。
base64.h
#ifdef __cplusplus
extern "C" {
#endif char * base64_encode( const unsigned char * bindata, char * base64, int binlength );
int base64_decode( const char * base64, unsigned char * bindata ); #ifdef __cplusplus
}
#endif
base64.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "base64.h" #ifndef MAX_PATH
#define MAX_PATH 256
#endif const char * base64char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; char * base64_encode( const unsigned char * bindata, char * base64, int binlength )
{
int i, j;
unsigned char current; for ( i = , j = ; i < binlength ; i += )
{
current = (bindata[i] >> ) ;
current &= (unsigned char)0x3F;
base64[j++] = base64char[(int)current]; current = ( (unsigned char)(bindata[i] << ) ) & ( (unsigned char)0x30 ) ;
if ( i + >= binlength )
{
base64[j++] = base64char[(int)current];
base64[j++] = '=';
base64[j++] = '=';
break;
}
current |= ( (unsigned char)(bindata[i+] >> ) ) & ( (unsigned char) 0x0F );
base64[j++] = base64char[(int)current]; current = ( (unsigned char)(bindata[i+] << ) ) & ( (unsigned char)0x3C ) ;
if ( i + >= binlength )
{
base64[j++] = base64char[(int)current];
base64[j++] = '=';
break;
}
current |= ( (unsigned char)(bindata[i+] >> ) ) & ( (unsigned char) 0x03 );
base64[j++] = base64char[(int)current]; current = ( (unsigned char)bindata[i+] ) & ( (unsigned char)0x3F ) ;
base64[j++] = base64char[(int)current];
}
base64[j] = '\0';
return base64;
} int base64_decode( const char * base64, unsigned char * bindata )
{
int i, j;
unsigned char k;
unsigned char temp[];
for ( i = , j = ; base64[i] != '\0' ; i += )
{
memset( temp, 0xFF, sizeof(temp) );
for ( k = ; k < ; k ++ )
{
if ( base64char[k] == base64[i] )
temp[]= k;
}
for ( k = ; k < ; k ++ )
{
if ( base64char[k] == base64[i+] )
temp[]= k;
}
for ( k = ; k < ; k ++ )
{
if ( base64char[k] == base64[i+] )
temp[]= k;
}
for ( k = ; k < ; k ++ )
{
if ( base64char[k] == base64[i+] )
temp[]= k;
} bindata[j++] = ((unsigned char)(((unsigned char)(temp[] << ))&0xFC)) |
((unsigned char)((unsigned char)(temp[]>>)&0x03));
if ( base64[i+] == '=' )
break; bindata[j++] = ((unsigned char)(((unsigned char)(temp[] << ))&0xF0)) |
((unsigned char)((unsigned char)(temp[]>>)&0x0F));
if ( base64[i+] == '=' )
break; bindata[j++] = ((unsigned char)(((unsigned char)(temp[] << ))&0xF0)) |
((unsigned char)(temp[]&0x3F));
}
return j;
}
base64解码的更多相关文章
- C# Base64解码 二进制输出
具体的:Base64编码解码还需要学习 /// <summary> /// base64 解码Excel下载 /// </summary> /// <param name ...
- 微信小程序之图片base64解码
不知道大家在做微信小程序的时候遇到base64解码的问题,我之前在做微信小程序的时候遇到base64解析图片一直有问题,所以在这里把遇到的问题和解决方案在这里记录一下: 在平时的项目中我们是直接用ba ...
- 将图片文件转化为字节数组字符串,并对其进行Base64编码处理,以及对字节数组字符串进行Base64解码并生成图片
实际开发中涉及图片上传并且量比较大的时候一般处理方式有三种 1.直接保存到项目中 最老土直接方法,也是最不适用的方法,量大对后期部署很不方便 2.直接保存到指定路径的服务器上.需要时候在获取,这种方式 ...
- SqlServer Base64解码中文
最近在做一个和拥有TurboCRM相关的项目,其中需要取出客户信息的联系人字段,经过查看,这个字段在存入时用Base64加密过了 这个功能在应用层实现是很方便的,但是由于一些特殊原因,只能放到SqlS ...
- python3 base64解码出现TypeError:Incorrect padding
今天在解决爬虫对加密参数的分析时,需要使用到base64解码.但是过程中出现了TypeError:Incorrect padding的错误提示.以下是解决方法,以便查阅. 其实正常使用base64是不 ...
- 【java工具类】对字节数组字符串进行Base64解码并生成图片
import java.io.File;import java.io.FileOutputStream;import java.io.OutputStream;import org.springfra ...
- erlang的base64解码问题
在收到客户端的数字签名signature后,需要对signature做base64的解码.代码如下所示: validate(SignedRequest) -> RequestParts = st ...
- bootstrap-wysiwyg 结合 base64 解码 .net bbs 图片操作类 (二) 图片裁剪
图片裁剪参见: http://deepliquid.com/projects/Jcrop/demos.php?demo=thumbnail 一个js插件 http://www.mikes ...
- bootstrap-wysiwyg 结合 base64 解码 .net bbs 图片操作类
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Dr ...
随机推荐
- 四种方式实现波浪效果(CSS效果)
一)第一种方法 (1)HTML结构 <body> <div class="animate wave"> <div class="w1&quo ...
- 数据库与数据仓库的比较Hbase——Hive
数据仓库(Data Warehouse)是一个面向主题的(Subject Oriented).集成的(Integrate).相对稳定的(Non-Volatile).反映历史变化(Time Varian ...
- Scrum立会报告+燃尽图(十月十二日总第三次):视频相关工作
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2190 Scrum立会master:孙赛佳 一.小组介绍 组长:付佳 组员 ...
- CS小分队第一阶段冲刺站立会议(5月13日)
昨日成果:昨日由于课程满课,未进行项目的制作 遇到困难:/ 今天计划:为2048和扫雷添加游戏音效,和组员一起合作对扫雷进行外观美化,学习程序生成时渐隐等特效
- 团队Alpha冲刺(八)
目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...
- alpha6/10
队名:Boy Next Door 燃尽图 晗(组长) 今日完成 学习了css的一些基本操作. 明日工作 抽空把javascript的基本操作学习一下 还剩下哪些任务 微信API还有京东钱包的API. ...
- C#高级编程 (第六版) 学习 第四章:继承
第四章 继承 1,继承的类型 实现继承: 一个类派生于一个基类型,拥有该基类型所有成员字段和函数. 接口继承 一个类型只继承了函数的签名,没有继承任何实现代码. 2,实现继承 class MyDe ...
- winform 弹出窗体指定位置
在启动一个程序时,我们希望窗口显示的位置处于屏幕的正中心,可以如下设置: MainForm mainForm = new MainForm(); mainForm.StartPosition = Fo ...
- 【Leetcode】 328. Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...
- 虚拟机Centos设置静态IP
首先确保虚拟网卡(VMware Network Adapter VMnet8)是开启的,然后在windows的命令行里输入“ipconfig /all”,找到VMware Network Adapte ...