parent
dc5a3ce852
commit
3317156b82
|
@ -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;
|
//
|
||||||
|
// byte[] aesDecode = CryptoHelper.aes256Decryption(aesCode, key);
|
||||||
|
// Assert.assertEquals(new String(aesDecode), srcTest);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// if (val.startsWith("git.commit.id=")) {
|
// @Test
|
||||||
// password = val.substring("git.commit.id=".length());
|
// 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) {
|
||||||
|
//// 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));
|
||||||
// }
|
// }
|
||||||
// }
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue