OpenEuler树莓派基础实验
- 参考https://www.cnblogs.com/rocedu/p/14615565.html 完成OpenEuler的安装,提交过程博客和截图
- 参考https://www.cnblogs.com/rocedu/p/14617763.html完成OpenSSL的安装,并测试,提交代码截图
- 参考附件,至少完成第三章的实验,提交过程博客链接
[toc]
一、安装Openeuler
下载镜像
首先下载OpenEuler官方iso镜像进行安装。
openeuler官网:https://www.openeuler.org/zh/
下载页面:https://www.openeuler.org/zh/download/
版本:
image.png
下载链接:https://repo.openeuler.org/openEuler-20.03-LTS-SP2/ISO/x86_64/openEuler-20.03-LTS-SP2-x86_64-dvd.iso
配置虚拟机

image.png
VMware自动安装

image.png
安装图形化界面
参考:https://blog.csdn.net/chenqioulin/article/details/116590588
依次输入:
sudo yum update #更新源
sudo yum install dde #安装图形界面
sudo systemctl set-default graphical.target #设置使用图形界面启动
sudo reboot #重新启动
如果无法成功安装,注意检查是否联网,同时检查源是否有效。
- 检查联网
在虚拟机设置使用NAT或者桥接连接网络,然后使用ping测试是否连接。
ping www.baidu.com
如果无法连接,使用命令dhclient使用DHCP进行联网。
启动可视化OpenEuler

image.png
OpenSSL安装及测试
根据链接安装OpenSSL,运行OpenSSL

image.png
openssl测试与使用
-
使用help查看帮助
image.png -
使用openssl help xxsubcmd或openssl xxsubcmd --help查看子命令的帮助
下图为查看rsa的帮助
image.png -
使用管道计算摘要:如计算besti20191227的sm3摘要就可以使用命令echo "besti20191227" | openssl sm3来完成。
效果如图:
image.png -
计算某文件的摘要:使用openssl sm3 filename完成。
image.png
编程测试openssl
- 使用代码进行测试
#include <stdio.h>
#include <openssl/evp.h>
int main(){
OpenSSL_add_all_algorithms();
return 0;
}

image.png
函数OpenSSL_add_all_algorithms()的作用是将所有算法载入。使用./to;echo $?则是打印出主函数的返回值。
- 使用老师给出的base64代码进行编译,测试。
#include <stdio.h>
#include <string.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
//Base64编码
void tEVP_Encode()
{
EVP_ENCODE_CTX *ctx;
ctx = EVP_ENCODE_CTX_new(); //EVP编码结构体
unsigned char in[1024]; //输入数据缓冲区
int inl; //输入数据长度
char out[2048]={0}; //输出数据缓冲区
int outl; //输出数据长度
FILE *infp; //输入文件句柄
FILE *outfp; //输出文件句柄
infp = fopen("test.dat","rb");//打开待编码的文件
if(infp == NULL)
{
printf("Open File \"Test.dat\" for Read Err.\n");
return;
}
outfp = fopen("test.txt","w");//打开编码后保存的文件
if(outfp == NULL)
{
printf("Open File \"test.txt\" For Write Err.\n");
return;
}
EVP_EncodeInit(ctx);//Base64编码初始化
printf("文件\"Test.dat\" Base64编码后为:\n");
//循环读取原文,并调用EVP_EncodeUpdate计算Base64编码
while(1)
{
inl = fread(in,1,1024,infp);
if(inl <= 0)
break;
EVP_EncodeUpdate(ctx,out,&outl,in,inl);//编码
fwrite(out,1,outl,outfp);//输出编码结果到文件
printf("%s",out);
}
EVP_EncodeFinal(ctx,out,&outl);//完成编码,输出最后的数据。
fwrite(out,1,outl,outfp);
printf("%s",out);
fclose(infp);
fclose(outfp);
printf("对文件\"Test.dat\" Base64编码完成,保存到\"test.txt\"文件.\n\n\n");
}
//Base64解码
void tEVP_Decode()
{
EVP_ENCODE_CTX *ctx;
ctx = EVP_ENCODE_CTX_new(); //EVP编码结构体
char in[1024]; //输入数据缓冲区
int inl; //输入数据长度
unsigned char out[1024]; //输出数据缓冲区
int outl; //输出数据长度
FILE *infp; //输入文件句柄
FILE *outfp; //输出文件句柄
infp = fopen("test.txt","r");//打开待解码的文件
if(infp == NULL)
{
printf("Open File \"Test.txt\" for Read Err.\n");
return;
}
outfp = fopen("test-1.dat","wb");//打开解码后保存的文件
if(outfp == NULL)
{
printf("Open File \"test-1.txt\" For Write Err.\n");
return;
}
EVP_DecodeInit(ctx);//Base64解码初始化
printf("开始对文件\"Test.txt\" Base64解码...\n\n");
//循环读取原文,并调用EVP_DecodeUpdate进行Base64解码
while(1)
{
inl = fread(in,1,1024,infp);
if(inl <= 0)
break;
EVP_DecodeUpdate(ctx,out,&outl,in,inl);//Base64解码
fwrite(out,1,outl,outfp);//输出到文件
}
EVP_DecodeFinal(ctx,out,&outl);//完成解码,输出最后的数据。
fwrite(out,1,outl,outfp);
fclose(infp);
fclose(outfp);
printf("对文件\"Test.txt\" Base64解码完成,保存为\"test-1.dat\"\n\n\n");
}
int main()
{
tEVP_Encode();
tEVP_Decode();
return 0;
}
-
测试成功,截图如下
image.png





