Ai
1 Star 0 Fork 0

*&c++/webdisk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
hash.cc 697 Bytes
一键复制 编辑 原始数据 按行查看 历史
geoff 提交于 2023-08-09 23:32 +08:00 . initialize webdisk project
#include "hash.h"
#include "unixHeader.h"
#include <openssl/sha.h>
string Hash::sha1() const
{
int fd = open(_filename.c_str(), O_RDONLY);
if(fd < 0) {
perror("open");
return string();
}
SHA_CTX ctx;
SHA1_Init(&ctx);
char buff[1024] = {0};
while(1) {
int ret = read(fd, buff, 1024);
if(ret == 0) {
break;
}
SHA1_Update(&ctx, buff, ret);
bzero(buff, 1024);
}
unsigned char md[20] = {0};
SHA1_Final(md, &ctx);
string result;
char fragment[3] = {0};
for(int i = 0; i < 20; ++i) {
sprintf(fragment, "%02x", md[i]);
result+= fragment;
}
return result;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/learntocodewithc/webdisk.git
git@gitee.com:learntocodewithc/webdisk.git
learntocodewithc
webdisk
webdisk
master

搜索帮助