| | |
| | | file1 = VideoZipUtil.compressVideo(file, 800000, 128000, 1280, 720); |
| | | FJ = fileToByteArray(file1); |
| | | } |
| | | String sm3 = Sm3Util.calculateSM3Hash(fjhxz + "," + pssj + "," + lng + "," + lat + "," + gimbalYawDegree + "," + psjd + "," + pshgj + "," + psry + "," + zsdm); |
| | | |
| | | byte[] hash = sm3.getBytes(); // 注意:使用SM3或其他哈希算法来计算数据的哈希值 |
| | | String hxz = HashUtil.calculateHash((fjhxz + "," + pssj + "," + lng + "," + lat + "," + gimbalYawDegree + "," + psjd + "," + pshgj + "," + psry + "," + zsdm).getBytes()); |
| | | byte[] hash = hxz.getBytes(); // 注意:使用SM3或其他哈希算法来计算数据的哈希值 |
| | | // 加载私钥 |
| | | ECPrivateKeyParameters sm2PrivateKey = getSM2PrivateKey(); |
| | | // 使用SM2私钥对哈希值进行签名 |
| | |
| | | public class HashUtil { |
| | | public static String SM3Hash(File file) { |
| | | String filePath = String.valueOf(file); |
| | | String hashHex = ""; |
| | | try { |
| | | byte[] fileBytes = readFile(filePath); |
| | | byte[] hash = calculateHash(fileBytes); |
| | | hashHex = Hex.toHexString(hash); |
| | | return calculateHash(fileBytes); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return hashHex; |
| | | return ""; |
| | | } |
| | | |
| | | private static byte[] readFile(String filePath) throws IOException { |
| | | public static byte[] readFile(String filePath) throws IOException { |
| | | FileInputStream fis = new FileInputStream(filePath); |
| | | byte[] buffer = new byte[1024]; |
| | | int bytesRead; |
| | |
| | | fis.close(); |
| | | return sb.toString().getBytes(); |
| | | } |
| | | public static String calculateHash(byte[] data) { |
| | | byte[] md = new byte[32]; |
| | | SM3Digest sm3 = new SM3Digest(); |
| | | sm3.update(data, 0, data.length); |
| | | sm3.doFinal(md, 0); |
| | | String s = new String(Hex.encode(md)); |
| | | return s.toUpperCase(); |
| | | } |
| | | |
| | | private static byte[] calculateHash(byte[] input) { |
| | | SM3Digest digest = new SM3Digest(); |
| | | digest.update(input, 0, input.length); |
| | | byte[] hash = new byte[digest.getDigestSize()]; |
| | | digest.doFinal(hash, 0); |
| | | return hash; |
| | | public static void main(String[] args) { |
| | | File file = new File("D:\\drone\\src\\main\\resources\\FJ_1s.jpeg"); |
| | | System.out.println(SM3Hash(file)); |
| | | } |
| | | } |