帮我写一份用SHA-1加密文件的详细C++代码
时间: 2023-03-10 07:56:06 浏览: 79
SHA-1加密文件的C代码可以这样实现:#include <stdio.h>
#include <openssl/sha.h>int main(int argc, char *argv[])
{
unsigned char digest[SHA_DIGEST_LENGTH];
char string[] = "要加密的文件"; SHA1((unsigned char*)&string, strlen(string), (unsigned char*)&digest); char mdString[SHA_DIGEST_LENGTH*2+1];
for(int i = 0; i < SHA_DIGEST_LENGTH; i++)
sprintf(&mdString[i*2], "%02x", (unsigned int)digest[i]); printf("SHA1加密得到的结果是: %s\n", mdString); return 0;
}
相关问题
帮我写一份用SHA-1加密文本文件的C++代码
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<openssl/sha.h> int main()
{
FILE* fp;
char file_data[100];
unsigned char digest[SHA_DIGEST_LENGTH]; fp = fopen("要加密的文本文件.txt", "r");
fgets(file_data, 100, fp); SHA1(file_data, strlen(file_data), digest); printf("SHA1加密的结果是: \n");
for(int i = 0; i <SHA_DIGEST_LENGTH; i++)
{
printf("%02x", digest[i]);
} printf("\n");
return 0;
}
帮我写一份用SHA-1加密文件的代码
SHA-1加密文件的代码如下:
//计算SHA-1哈希
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] result = md.digest(inputBytes);
//将字节转化为十六进制字符串
StringBuffer sb = new StringBuffer();
for (int i = 0; i < result.length; i++) {
sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));
}
//返回加密结果
return sb.toString();
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)