toys/simple-http-server-c/source/main.cpp

70 lines
1.5 KiB
C++

#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
// #include "lane_fitter_least_square.h"
extern "C" {
#include "base64.h"
// #include "aes.h"
#include "aes_util.h"
#include "sha.h"
}
static void _encode(const void * buffer, size_t bufferSize, void ** output, size_t * outputSize)
{
char * tmpBuffer = NULL;
size_t size = 0;
size_t tmpOutputSize = Base64_GetCodeLength(bufferSize);
tmpBuffer = (char *)malloc(tmpOutputSize + 1);
size = Base64_Encode((const char *)buffer, bufferSize, tmpBuffer);
tmpBuffer[size] = 0;
*output = tmpBuffer;
*outputSize = size;
}
static void _decode(const std::vector<char>& buffer, std::vector<char>& output)
{
output.resize(Base64_GetDataLength(buffer.size()));
size_t size = Base64_Decode(&buffer[0], buffer.size(), &output[0]);
output.resize(size);
}
int main()
{
unsigned char in[] = "test key";
unsigned char key[32];
memset(key, 0, 32);
sha256(in, strlen((const char *)in), key);
printf("sha256\n");
for(int i = 0; i < 32; i++)
{
printf("%x", key[i]);
}
std::cout << std::endl;
char *output;
size_t outputSize;
std::vector<char> enc;
std::vector<char> out;
const char *encrypt = "P37w+VZImNgPEO1RBhJ6RtKl7n6zymIbEG1pReEzghk=";
enc.assign(encrypt, encrypt + strlen(encrypt));
_decode(enc, out);
printf("base64 decode\n");
std::cout << encrypt << std::endl;
for(auto c : out)
{
printf("%x", c);
}
std::cout << std::endl;
return 0;
}