SOL9 Sample: Base64EncDec
|
1 Screenshot
2 Source code
/*
* Base64EncDec.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
//2011/09/03 Modified to use Bytes class instead of ByteArray class.
#include <sol\Base64Encoder.h>
#include <sol\Base64Decoder.h>
void dump(unsigned char* data, size_t len)
{
for (size_t i = 0; i<len; i++) {
if (i >0 && (i %16) == 0) {
_tprintf(_T("\n"));
}
_tprintf(_T("%02X "), data[i]);
}
_tprintf(_T("\n"));
}
void _tmain(int argc, TCHAR** argv)
{
unsigned char input[128];
for (int i = 0; i<sizeof(input); i++) {
input[i] = (i+1)*(i+2)*(i+3) % 128;
}
_tprintf(_T("Original bytes len=%d\n"), sizeof(input));
dump(input, sizeof(input));
Base64Encoder encoder;
//char* encoded = encoder.encode(input, sizeof(input));
Bytes byteArray(input, sizeof(input));
char* encoded = encoder.encode(byteArray);
_tprintf(_T("Encoded=[%s]\n"), (const TCHAR*)String(encoded));
String encString;
encoder.encode(byteArray, encString);
_tprintf(_T("Encoded2=[%s]\n"), (const TCHAR*)encString);
Base64Decoder decoder;
unsigned char* decoded = NULL;
unsigned int decLen = 0;
decoder.decode(encoded, strlen(encoded), &decoded, &decLen);
Bytes decByteArray;
decoder.decode(encoded, decByteArray);
_tprintf(_T("Decoded declen=%d\n"), decLen);
dump(decoded, decLen);
unsigned char* contents = decByteArray.getContents();
int size = decByteArray.getSize();
_tprintf(_T("Decoded2 declen=%d\n"), size);
dump(contents, size);
_tprintf(_T("delete encoded\n"));
delete [] encoded;
_tprintf(_T("delete decoded\n"));
delete [] decoded;
}
Last modified: 2 May 2016
Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.