added base64test.cpp

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-07-21 19:34:04 +08:00
parent 4bc6cf4ef0
commit 7ca8c39354
2 changed files with 52 additions and 1 deletions

View File

@ -106,3 +106,6 @@ cm_example_project("android" AndroidDeviceAnalysis)
add_executable(PAttribTest utils/PAttribTest.cpp)
cm_example_project("utils" PAttribTest)
add_executable(Base64Test utils/base64test.cpp)
cm_example_project("utils" Base64Test)

48
utils/base64test.cpp Normal file
View File

@ -0,0 +1,48 @@
#include<hgl/util/Crypt.h>
#include<hgl/io/MemoryOutputStream.h>
#include<iostream>
using namespace hgl;
using namespace hgl::io;
using namespace hgl::crypt;
using namespace std;
int main(int,char **)
{
constexpr uchar test_str[]="BASE64 Decode and Encode"; //测试编解码用字符串
cout<<"Origin: "<<test_str<<endl;
MemoryOutputStream mos;
if(!base64_encode(&mos,test_str,strlen(test_str)))
{
cout<<"encode error!"<<endl;
return(-1);
}
int64 len;
uchar *tmp;
tmp=(uchar *)mos.CreateCopyData(&len);
cout<<"Encode: "<<tmp<<endl;
mos.ClearData();
if(!base64_decode(&mos,tmp,len))
{
cout<<"decode error!"<<endl;
return(-2);
}
delete[] tmp;
tmp=(uchar *)mos.CreateCopyData(&len);
cout<<"Decode: "<<tmp<<endl<<endl;
delete[] tmp;
return 0;
}