资源简介
SHA1withRSA算法不依赖第三方库
代码片段和文件信息
#include “stdafx.h“
#include“stdlib.h“
#include“stdio.h“
#include
#include “base64.h“
#include “bigint.h“
//浠ヤ笅鏄?base64.h 鐨勫唴瀹?
size_t base64_Decode(char *pDest const char *pSrc size_t srclen);
size_t base64_Encode(char *pDest const char *pSrc size_t srclen);
//浠ヤ笅鏄?base64.cpp 鐨勫唴瀹?
BYTE Decode_GetByte(char c);
char Encode_GetChar(BYTE num);
//===================================
// base64 瑙g爜
//===================================
BYTE Decode_GetByte(char c)
{
if(c == ‘+‘)
return 62;
else if(c == ‘/‘)
return 63;
else if(c <= ‘9‘)
return (BYTE)(c - ‘0‘ + 52);
else if(c == ‘=‘)
return 64;
else if(c <= ‘Z‘)
return (BYTE)(c - ‘A‘);
else if(c <= ‘z‘)
return (BYTE)(c - ‘a‘ + 26);
return 64;
}
//瑙g爜
size_t base64_Decode(char *pDest const char *pSrc size_t srclen)
{
BYTE input[4];
size_t i index = 0;
for(i = 0; i < srclen; i += 4)
{
//byte[0]
input[0] = Decode_GetByte(pSrc[i]);
input[1] = Decode_GetByte(pSrc[i + 1]);
pDest[index++] = (input[0] << 2) + (input[1] >> 4);
//byte[1]
if(pSrc[i + 2] != ‘=‘)
{
input[2] = Decode_GetByte(pSrc[i + 2]);
pDest[index++] = ((input[1] & 0x0f) << 4) + (input[2] >> 2);
}
//byte[2]
if(pSrc[i + 3] != ‘=‘)
{
input[3] = Decode_GetByte(pSrc[i + 3]);
pDest[index++] = ((input[2] & 0x03) << 6) + (input[3]);
}
}
//null-terminator
pDest[index] = 0;
return index;
}
//===================================
// base64 缂栫爜
//===================================
char Encode_GetChar(BYTE num)
{
return
“ABCDEFGHIJKLMNOPQRSTUVWXYZ“
“abcdefghijklmnopqrstuvwxyz“
“0123456789“
“+/=“[num];
}
//缂栫爜
size_t base64_Encode(char *pDest const char *pSrc size_t srclen)
{
BYTE input[3] output[4];
size_t i index_src = 0 index_dest = 0;
for(i = 0; i < srclen; i += 3)
{
//char [0]
input[0] = pSrc[index_src++];
output[0] = (BYTE)(input[0] >> 2);
pDest[index_dest++] = Encode_GetChar(output[0]);
//char [1]
if(index_src < srclen)
{
input[1] = pSrc[index_src++];
output[1] = (BYTE)(((input[0] & 0x03) << 4) + (input[1] >> 4));
pDest[index_dest++] = Encode_GetChar(output[1]);
}
else
{
output[1] = (BYTE)((input[0] & 0x03) << 4);
pDest[index_dest++] = Encode_GetChar(output[1]);
pDest[index_dest++] = ‘=‘;
pDest[index_dest++] = ‘=‘;
break;
}
//char [2]
if(index_src < srclen)
{
input[2] = pSrc[index_src++];
output[2] = (BYTE)(((input[1] & 0x0f) << 2) + (input[2] >> 6));
pDest[index_de
- 上一篇:一步一步教你制作上位机图像处理软件
- 下一篇:精品课程网站答辩PPT
评论
共有 条评论