实验二——验收三

发布时间 2023-06-04 21:01:23作者: 20201325my

验收三

1. 你们小组项目中为了保护数据资产用了什么密码算法?
2. 如果用到了对称算法,提交相关生成密钥和对数据加密的代码截图
3. 如果用到了非对称算法,提交相关生成密钥对和对数据加密,签名验签的代码截图
4. 如果用到了其他算法,提交相关的代码截图

1.算法使用

①口令哈希值:sm3

②密钥生成:gmssl库中的rand()指令进行生成

③公文加解密:sm4

2.sm4介绍

代码:

public static void SM4encrypt(String filePath,String key) throws IOException {
			String cmd = "gmssl sm4 -cbc -encrypt -in " + filePath + " -out " + filePath + ".en -key " + key + " -iv " + key;
			RunCmd.run(cmd);
		}
		
public static void SM4decrypt(String filePath,String key) throws IOException {
			String cmd = "gmssl sm4 -cbc -decrypt -in " + filePath + ".en -out " + filePath + " -key " + key + " -iv " + key;
			RunCmd.run(cmd);
		}

数据库:



存储为加密后文件

用户下载后解密为明文:

4.sm3介绍

public static String SM3(String data) throws IOException {
			List<String> commandArr = new ArrayList<>();
			commandArr.add("/bin/sh");
			commandArr.add("-c");
			String cmd = "echo "+data+" | gmssl sm3";
			commandArr.add(cmd);
			String result = RunCmd.run(commandArr.toArray(new String[commandArr.size()]));
			System.out.println(result);
			return result;
		}