| | |
| | | String filePath = String.valueOf(file); |
| | | try { |
| | | byte[] fileBytes = readFile(filePath); |
| | | return calculateHash(fileBytes); |
| | | return sm3(fileBytes); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | fis.close(); |
| | | return sb.toString().getBytes(); |
| | | } |
| | | public static String calculateHash(byte[] data) { |
| | | public static String sm3(byte[] data) { |
| | | byte[] md = new byte[32]; |
| | | SM3Digest sm3 = new SM3Digest(); |
| | | sm3.update(data, 0, data.length); |
| | |
| | | String s = new String(Hex.encode(md)); |
| | | return s.toUpperCase(); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | File file = new File("D:\\drone\\src\\main\\resources\\FJ_1s.jpeg"); |
| | | System.out.println(SM3Hash(file)); |
| | | System.out.println(SM3Hash(new File("src/main/resources/FJ_11.jpeg"))); |
| | | } |
| | | } |