mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bug
This commit is contained in:
@@ -300,9 +300,11 @@ public class SymmetricCrypto implements SymmetricEncryptor, SymmetricDecryptor,
|
||||
throw new CryptoException(e);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
// issue#I4EMST@Gitee
|
||||
// CipherOutputStream必须关闭,才能完全写出
|
||||
IoUtil.close(cipherOutputStream);
|
||||
if (isClose) {
|
||||
IoUtil.close(data);
|
||||
IoUtil.close(cipherOutputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -351,9 +353,11 @@ public class SymmetricCrypto implements SymmetricEncryptor, SymmetricDecryptor,
|
||||
throw new CryptoException(e);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
// issue#I4EMST@Gitee
|
||||
// CipherOutputStream必须关闭,才能完全写出
|
||||
IoUtil.close(cipherInputStream);
|
||||
if (isClose) {
|
||||
IoUtil.close(data);
|
||||
IoUtil.close(cipherInputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -81,4 +81,6 @@ public class SmTest {
|
||||
String digest = hMac.digestHex(content);
|
||||
Assert.assertEquals("493e3f9a1896b43075fbe54658076727960d69632ac6b6ed932195857a6840c6", digest);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,51 @@
|
||||
package cn.hutool.crypto.test.symmetric;
|
||||
|
||||
import cn.hutool.crypto.symmetric.SM4;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* https://gitee.com/dromara/hutool/issues/I4EMST
|
||||
*/
|
||||
public class Sm4StreamTest {
|
||||
|
||||
private static final SM4 sm4 = new SM4();
|
||||
|
||||
private static final boolean IS_CLOSE = false;
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sm4Test(){
|
||||
String source = "d:/test/sm4_1.txt";
|
||||
String target = "d:/test/sm4_2.data";
|
||||
String target2 = "d:/test/sm4_3.txt";
|
||||
encrypt(source, target);
|
||||
decrypt(target, target2);
|
||||
}
|
||||
|
||||
public static void encrypt(String source, String target) {
|
||||
try (InputStream input = new FileInputStream(source);
|
||||
OutputStream out = new FileOutputStream(target)) {
|
||||
sm4.encrypt(input, out, IS_CLOSE);
|
||||
System.out.println("============encrypt end");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void decrypt(String source, String target) {
|
||||
try (InputStream input = new FileInputStream(source);
|
||||
OutputStream out = new FileOutputStream(target)) {
|
||||
sm4.decrypt(input, out, IS_CLOSE);
|
||||
System.out.println("============decrypt end");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user