REM:
1. 清理部分单测用例
This commit is contained in:
HuangXin 2020-09-27 18:45:32 +08:00
parent dc5a3ce852
commit 3317156b82
1 changed files with 53 additions and 54 deletions

View File

@ -8,7 +8,6 @@ import org.junit.Test;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException; import javax.crypto.NoSuchPaddingException;
import java.io.InputStream;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
@ -81,59 +80,59 @@ public class CryptoHelperTest {
Assert.assertEquals(new String(aesDecode), srcTest); Assert.assertEquals(new String(aesDecode), srcTest);
} }
@Test // @Test
public void t4_aes256Test() throws IllegalBlockSizeException, InvalidKeyException, BadPaddingException, // public void t4_aes256Test() throws IllegalBlockSizeException, InvalidKeyException, BadPaddingException,
NoSuchAlgorithmException, NoSuchPaddingException { // NoSuchAlgorithmException, NoSuchPaddingException {
String srcTest = "hello word"; // String srcTest = "hello word";
String key = "hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40"; // String key = "hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40";
byte[] aesCode = CryptoHelper.aes256Encryption(srcTest.getBytes(StandardCharsets.UTF_8), key); // byte[] aesCode = CryptoHelper.aes256Encryption(srcTest.getBytes(StandardCharsets.UTF_8), key);
String showText = CryptoHelper.base64Encryption(aesCode); // String showText = CryptoHelper.base64Encryption(aesCode);
Assert.assertEquals(showText, "3sTXo4P2/pGQEfL9UJ/wRQ==");
byte[] aesDecode = CryptoHelper.aes256Decryption(aesCode, key);
Assert.assertEquals(new String(aesDecode), srcTest);
}
@Test
public void t5_aes256EncryptionTest() throws IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
InputStream is = ClassLoader.getSystemResourceAsStream("git.properties");
assert is != null;
String password;
String testEncValue = "hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40";
String testEncValue1 = "P3mq9iSIvQcvfyfdWR8sAnfAadO";
String testEncValue2 = "h0K0_8u";
// BufferedReader reader = new BufferedReader(new InputStreamReader(is));
// log.info("Version Information:");
// while (true) {
// String val = reader.readLine();
// log.info("{}", val);
// //
// if (val == null) { // Assert.assertEquals(showText, "3sTXo4P2/pGQEfL9UJ/wRQ==");
// break;
// }
// //
// if (val.startsWith("git.commit.id=")) { // byte[] aesDecode = CryptoHelper.aes256Decryption(aesCode, key);
// password = val.substring("git.commit.id=".length()); // Assert.assertEquals(new String(aesDecode), srcTest);
// } // }
// } //
// @Test
password = "63debfca1d2dc72af38014a7bb6f567202cc1345" + "cmcc@10086!"; // public void t5_aes256EncryptionTest() throws IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
// InputStream is = ClassLoader.getSystemResourceAsStream("git.properties");
byte[] encode = CryptoHelper.aes256Encryption(testEncValue.getBytes(StandardCharsets.UTF_8), password); // assert is != null;
Assert.assertEquals(CryptoHelper.base64Encryption(encode), "Trf2LEETes3oKnY1CF7LINcm2KlJbJxHIyvERz2174CTzQEhJtuo+PnO+fR3eDf+"); // String password;
log.info("Encrypt with key {}: {} --> {}", password, testEncValue, // String testEncValue = "hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40";
CryptoHelper.base64Encryption(encode)); // String testEncValue1 = "P3mq9iSIvQcvfyfdWR8sAnfAadO";
// String testEncValue2 = "h0K0_8u";
encode = CryptoHelper.aes256Encryption(testEncValue1.getBytes(StandardCharsets.UTF_8), password); //
Assert.assertEquals(CryptoHelper.base64Encryption(encode), "JPYbpchhllvf6M+uolBFYOgM2fSyqGChRcnzoOCt6WM="); //// BufferedReader reader = new BufferedReader(new InputStreamReader(is));
log.info("Encrypt with key {}: {} --> {}", password, testEncValue1, //// log.info("Version Information:");
CryptoHelper.base64Encryption(encode)); //// while (true) {
//// String val = reader.readLine();
encode = CryptoHelper.aes256Encryption(testEncValue2.getBytes(StandardCharsets.UTF_8), password); //// log.info("{}", val);
Assert.assertEquals(CryptoHelper.base64Encryption(encode), "eBlCdflAlcnta81xW9f86A=="); ////
log.info("Encrypt with key {}: {} --> {}", password, testEncValue2, //// if (val == null) {
CryptoHelper.base64Encryption(encode)); //// break;
} //// }
////
//// if (val.startsWith("git.commit.id=")) {
//// password = val.substring("git.commit.id=".length());
//// }
//// }
//
// password = "63debfca1d2dc72af38014a7bb6f567202cc1345" + "cmcc@10086!";
//
// byte[] encode = CryptoHelper.aes256Encryption(testEncValue.getBytes(StandardCharsets.UTF_8), password);
// Assert.assertEquals(CryptoHelper.base64Encryption(encode), "Trf2LEETes3oKnY1CF7LINcm2KlJbJxHIyvERz2174CTzQEhJtuo+PnO+fR3eDf+");
// log.info("Encrypt with key {}: {} --> {}", password, testEncValue,
// CryptoHelper.base64Encryption(encode));
//
// encode = CryptoHelper.aes256Encryption(testEncValue1.getBytes(StandardCharsets.UTF_8), password);
// Assert.assertEquals(CryptoHelper.base64Encryption(encode), "JPYbpchhllvf6M+uolBFYOgM2fSyqGChRcnzoOCt6WM=");
// log.info("Encrypt with key {}: {} --> {}", password, testEncValue1,
// CryptoHelper.base64Encryption(encode));
//
// encode = CryptoHelper.aes256Encryption(testEncValue2.getBytes(StandardCharsets.UTF_8), password);
// Assert.assertEquals(CryptoHelper.base64Encryption(encode), "eBlCdflAlcnta81xW9f86A==");
// log.info("Encrypt with key {}: {} --> {}", password, testEncValue2,
// CryptoHelper.base64Encryption(encode));
// }
} }