libtomcrypt编译
㈠ 请教BCB里的Base64加密有没有能直接加密文件流的方法
下载 TomCrypt 通用加密库
编译出 Lib
--------------------------------------------------------------------
// 调用
String a = "";
File2Text(&a, "c:\\1.jpg");
Text2File("c:\\2.jpg", &a);
---------------------------------------------------------------------
// 功能实现,自己在函数内加上一些可靠性验证也就差不多了
int __fastcall Bin2Text(String* OutText, TMemoryStream* pMS)
{
/* 二进制流数据转换为 base64 码 */
// 初始化输出字符串
*OutText = "";
// 计算输出字符串长度
unsigned long OutStringSize = 4 * (((unsigned long)pMS->Size + 2) / 3) + 1;
// 设置输出字符串长度
OutText->SetLength( OutStringSize );
// 置内存流初始点
pMS->Position = 0;
// 开始转换
int Result = base64_encode (
(unsigned char*)pMS->Memory, (unsigned long)pMS->Size,
(unsigned char*)OutText->c_str(), &OutStringSize );
// 返回转换结果
return Result;
}
//---------------------------------------------------------------------------
int __fastcall File2Text(String *OutText, String Filename)
{
/* 输入文件转换为 base64 码 */
// 创建内存流
TMemoryStream* pMS = new TMemoryStream;
// 载入文件
pMS->LoadFromFile(Filename);
// 置指针初始位置
pMS->Position = 0;
// 开始转换,并将输出内容保存到 OutText
int Result = Bin2Text(OutText, pMS);
// 删除内存对象
delete pMS;
// 反馈结果
return Result;
}
//---------------------------------------------------------------------------
int __fastcall Text2File(String Filename, String* InText)
{
/* base64 码转换为 二进制文件 */
// 创建内存流
TMemoryStream* pMS = new TMemoryStream;
// 通过输入的 base64 指针信息转换为 二进制流
int Result = Text2Bin(pMS, InText);
// 置指针初始位值,保存文件
pMS->Position = 0;
pMS->SaveToFile(Filename);
// 删除对象
delete pMS;
// 反馈结果
return Result;
}
//---------------------------------------------------------------------------
int __fastcall Text2Bin(TMemoryStream* pMS, String* InText)
{
/* base64 转换为二进制流 */
// 获得 base64 长度
unsigned long* pStrSize = new unsigned long;
*pStrSize = InText->Length();
// 获得 base64 长度
unsigned long StrSize = InText->Length();
// 清除对象信息
pMS->Clear();
// 设置长度
pMS->Size = StrSize;
// 转换
int Result = base64_decode (
(unsigned char*)InText->c_str(),
StrSize,
(unsigned char*)pMS->Memory,
pStrSize
);
// 重新设置实际长度
pMS->Size = *pStrSize;
// 删除临时对象
delete pStrSize;
// 置内存流初始位置
pMS->Position = 0;
// 反馈信息
return Result;
}
//---------------------------------------------------------------------------
㈡ 在ubuntu 10.04下编译buildroot-v23434提示stdio.h:286: error: expected declaration specifiers错误
下载buildroot稳定版本V2012.02试试
