added base64test.cpp
This commit is contained in:
parent
4bc6cf4ef0
commit
7ca8c39354
@ -105,4 +105,7 @@ cm_example_project("android" AndroidDeviceAnalysis)
|
||||
####################################################################################################
|
||||
|
||||
add_executable(PAttribTest utils/PAttribTest.cpp)
|
||||
cm_example_project("utils" PAttribTest)
|
||||
cm_example_project("utils" PAttribTest)
|
||||
|
||||
add_executable(Base64Test utils/base64test.cpp)
|
||||
cm_example_project("utils" Base64Test)
|
48
utils/base64test.cpp
Normal file
48
utils/base64test.cpp
Normal 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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user