|
@@ -8,6 +8,9 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import javax.crypto.Mac;
|
|
import javax.crypto.Mac;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.io.InputStream;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.security.KeyFactory;
|
|
import java.security.KeyFactory;
|
|
|
import java.security.MessageDigest;
|
|
import java.security.MessageDigest;
|
|
@@ -99,6 +102,33 @@ public class AesUtils {
|
|
|
return "";
|
|
return "";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 文件转为字符串
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param file
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String turnMultipartFileToString(MultipartFile file) {
|
|
|
|
|
+ if (file != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return new String(toByteArray(file.getInputStream()), StandardCharsets.UTF_8);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static byte[] toByteArray(InputStream inputStream) throws IOException {
|
|
|
|
|
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
|
|
|
|
+ byte[] data = new byte[8192];
|
|
|
|
|
+ int nRead;
|
|
|
|
|
+ while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
|
|
|
|
|
+ buffer.write(data, 0, nRead);
|
|
|
|
|
+ }
|
|
|
|
|
+ return buffer.toByteArray();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static PublicKey initializeSM3WithSM2PublicKey(String publicKeyStr) throws Exception {
|
|
public static PublicKey initializeSM3WithSM2PublicKey(String publicKeyStr) throws Exception {
|
|
|
// 将字节转换为PublicKey
|
|
// 将字节转换为PublicKey
|
|
|
Security.addProvider(new BouncyCastleProvider());
|
|
Security.addProvider(new BouncyCastleProvider());
|