|
@@ -7,24 +7,6 @@ class DataEncryptionUtilTest {
|
|
|
@Test
|
|
|
void rsaEncodeAndDecrypt() throws Exception {
|
|
|
|
|
|
- String type = "RSA";
|
|
|
-
|
|
|
- // 将公钥和私钥转换为Base64编码的字符串
|
|
|
-// String publicKeyString = Base64.getEncoder().encodeToString(publicKey.getEncoded());
|
|
|
- String publicKeyString = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCfbyuRrG+YUX7dy/ziNqxsPP7YPKUnti+m3yDfJdN2MKa1GcIvPkfIXZ5EfEkoI9m5NwPfeC+kwM1fDWxvY/oMo/lWpIAo2zkhxssIXSkukF79I0N4vH+JAcuHN7llPYgMGkkyIe/FP/A1ZkGEayjMMqm4cfPs3vthsWgdmbnxHwIDAQAB";
|
|
|
-// String privateKeyString = Base64.getEncoder().encodeToString(privateKey.getEncoded());
|
|
|
- String privateKeyString = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJ9vK5Gsb5hRft3L/OI2rGw8/tg8pSe2L6bfIN8l03YwprUZwi8+R8hdnkR8SSgj2bk3A994L6TAzV8NbG9j+gyj+VakgCjbOSHGywhdKS6QXv0jQ3i8f4kBy4c3uWU9iAwaSTIh78U/8DVmQYRrKMwyqbhx8+ze+2GxaB2ZufEfAgMBAAECgYAyMdTcuxYzNU0k1SkbqyzjstxlBcrVUtVzywHVX1pQ9oY1tBNfvlLpMRg35Y0+tvLADiMJAxS04QKHb3l5JFe/jE24hNxMj2h9JfxO36bGblyqZ7PlS+5/pvXdVaFYolN+5Rocf63/Iq2RSCb8W3D5uUQqLwO/i1iFQT+UROUA4QJBAOvvOJSB4BIu4VD/6XGqZ5cLU3DMtwzHIyvTTH2REGF33eEHc0z83VYi4xbUDGxvDD1d58bPqkpnvJiByXmYVa8CQQCs/mHfpO8fDy7ZKGzs1u4eBsPowSnJLsGbY2mYiaawnHeeLYOaGEdtxRVk06+seTFLw5oi3FDJG8U8LP6FiGeRAkAjZiQeHBJrh/8kcREsjb23KurdDMoWL7a2N6DNYjuL9DklL0H8diAbcWaTIUOv7UVv26wP506MlV31n9uD0/hfAkBo3gwWtrT97wZHPepJ6ECQkylPf0kFXAKhX7Izdb5GcZNRn+WXFAC42jAN3wUvWIg5lWlqmIOgZeU6hUwFRpsBAkEAsSe8v0cho1YTdmXiGQ7uhUxZ455mrw81AdzmuvDxvWFLx1uHAZna9eylZsfbEa7Y9DcmakLJKGWaTvKvYc55ZQ==";
|
|
|
-
|
|
|
- System.out.println("public: " + publicKeyString);
|
|
|
- System.out.println("private: " + privateKeyString);
|
|
|
-
|
|
|
- String algorithm = "RSA/ECB/PKCS1Padding";
|
|
|
-// String data = """
|
|
|
-// {
|
|
|
-// "jdbcUrl": "jdbc:sqlite:systemset.sqlite",
|
|
|
-// "driverClassName": "org.sqlite.JDBC"
|
|
|
-// }
|
|
|
-// """;
|
|
|
String data = """
|
|
|
{
|
|
|
"jdbcUrl": "jdbc:mysql://120.26.64.82:3306/systemset",
|
|
@@ -36,182 +18,7 @@ class DataEncryptionUtilTest {
|
|
|
String decryptedData = DataEncryptionUtil.decryptRSAByPrivateKey(encryptedData);
|
|
|
System.out.println(data + ": " + encryptedData);
|
|
|
Assertions.assertEquals(data, decryptedData);
|
|
|
-// data = """
|
|
|
-// {
|
|
|
-// "jdbcUrl": "jdbc:sqlite:uniauth.sqlite",
|
|
|
-// "driverClassName": "org.sqlite.JDBC"
|
|
|
-// }
|
|
|
-// """;
|
|
|
-// encryptedData = DataEncryptionUtil.encryptByPublicKey(data, publicKeyString, type, algorithm);
|
|
|
-// decryptedData = DataEncryptionUtil.decryptByPrivateKey(encryptedData, privateKeyString, type, algorithm);
|
|
|
-// System.out.println(data + ": " + encryptedData);
|
|
|
-// Assertions.assertEquals(data, decryptedData);
|
|
|
-// data = """
|
|
|
-// {"type": "ES","connection": "{\\"jdbcUrl\\": \\"jdbc:sqlite:log.sqlite\\",\\"driverClassName\\": \\"org.sqlite.JDBC\\"}"}
|
|
|
-// """.trim();
|
|
|
-// encryptedData = DataEncryptionUtil.encryptByPublicKey(data, publicKeyString, type, algorithm);
|
|
|
-// decryptedData = DataEncryptionUtil.decryptByPrivateKey(encryptedData, privateKeyString, type, algorithm);
|
|
|
-// System.out.println(data + ": " + encryptedData);
|
|
|
-// Assertions.assertEquals(data, decryptedData);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void dec() throws Exception {
|
|
|
-
|
|
|
- String type = "RSA";
|
|
|
-
|
|
|
- // 将公钥和私钥转换为Base64编码的字符串
|
|
|
-// String publicKeyString = Base64.getEncoder().encodeToString(publicKey.getEncoded());
|
|
|
- String publicKeyString = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCfbyuRrG+YUX7dy/ziNqxsPP7YPKUnti+m3yDfJdN2MKa1GcIvPkfIXZ5EfEkoI9m5NwPfeC+kwM1fDWxvY/oMo/lWpIAo2zkhxssIXSkukF79I0N4vH+JAcuHN7llPYgMGkkyIe/FP/A1ZkGEayjMMqm4cfPs3vthsWgdmbnxHwIDAQAB";
|
|
|
-// String privateKeyString = Base64.getEncoder().encodeToString(privateKey.getEncoded());
|
|
|
- String privateKeyString = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJ9vK5Gsb5hRft3L/OI2rGw8/tg8pSe2L6bfIN8l03YwprUZwi8+R8hdnkR8SSgj2bk3A994L6TAzV8NbG9j+gyj+VakgCjbOSHGywhdKS6QXv0jQ3i8f4kBy4c3uWU9iAwaSTIh78U/8DVmQYRrKMwyqbhx8+ze+2GxaB2ZufEfAgMBAAECgYAyMdTcuxYzNU0k1SkbqyzjstxlBcrVUtVzywHVX1pQ9oY1tBNfvlLpMRg35Y0+tvLADiMJAxS04QKHb3l5JFe/jE24hNxMj2h9JfxO36bGblyqZ7PlS+5/pvXdVaFYolN+5Rocf63/Iq2RSCb8W3D5uUQqLwO/i1iFQT+UROUA4QJBAOvvOJSB4BIu4VD/6XGqZ5cLU3DMtwzHIyvTTH2REGF33eEHc0z83VYi4xbUDGxvDD1d58bPqkpnvJiByXmYVa8CQQCs/mHfpO8fDy7ZKGzs1u4eBsPowSnJLsGbY2mYiaawnHeeLYOaGEdtxRVk06+seTFLw5oi3FDJG8U8LP6FiGeRAkAjZiQeHBJrh/8kcREsjb23KurdDMoWL7a2N6DNYjuL9DklL0H8diAbcWaTIUOv7UVv26wP506MlV31n9uD0/hfAkBo3gwWtrT97wZHPepJ6ECQkylPf0kFXAKhX7Izdb5GcZNRn+WXFAC42jAN3wUvWIg5lWlqmIOgZeU6hUwFRpsBAkEAsSe8v0cho1YTdmXiGQ7uhUxZ455mrw81AdzmuvDxvWFLx1uHAZna9eylZsfbEa7Y9DcmakLJKGWaTvKvYc55ZQ==";
|
|
|
-
|
|
|
- System.out.println("public: " + publicKeyString);
|
|
|
- System.out.println("private: " + privateKeyString);
|
|
|
-
|
|
|
- String algorithm = "RSA/ECB/PKCS1Padding";
|
|
|
- String password = "V/A7EMJGarEct13FipYK3vP/plaSTuTk7tsE5TnO2M8S5u80NEFGKTmaV2Rl/6G9/y6wpU9RpQUdU4Ri8Ss+/PbR0/LqtIIWQ85pgEpS9lCcfPt3b0pNeQwQnuRDFtg/6z7dGW6MDPAuQtRYgiFIh1YF7qOYcQqG++iYgWBtMu4=";
|
|
|
-
|
|
|
- String decryptedData = DataEncryptionUtil.decryptByPrivateKey(password, privateKeyString, type, algorithm);
|
|
|
- System.out.println(decryptedData);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Test
|
|
|
- void encrypt() throws Exception {
|
|
|
- String password = DataEncryptionUtil.encryptRSAByPublicKey("""
|
|
|
- {
|
|
|
- "jdbcUrl": "jdbc:mysql://10.199.1.52:3306/uniauth",
|
|
|
- "username": "bigdata",
|
|
|
- "password": "N_y+)HOoB%K0"
|
|
|
- }
|
|
|
- """);
|
|
|
- System.out.println(password);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void decrypt() throws Exception {
|
|
|
- String string = DataEncryptionUtil.decryptRSAByPrivateKey("A0SelKtVJgLGot4XrMTnjv3/4KIKHcZb6tEXvLSqTown42q25BPSHsINRg42mrF8J2/vbwsQQtJWDs4DKVqc2kRkenu21FuOCuqmGxlINY7tBQxyJykK7IJ3Ovn7N7bsaX0PNnEcTgmNQpGrHxIgAc3uK1PYeZ1rTKMqlhNd+Jd6EMDvYPrsH/EtxrusM1s4S/BgKiOwSy7nUCjFlpczzxLJqRuQF8Ylz7ZqcNKkwsE78JOOOh/sPuTevO/6MkAGx+6T9/99M0RnGf2P9tegcKA0ioeTfzfqjAoUx74AzdozjLiPF0wqMJvICeAxHO0MQMYEqbDxXJ7dMBsu5fYyLxyTUKVsR17FIY3CiqlUsX2y2IlU/RqkaGJmZby5G2Tf5HkJm8Af3v4588BydS0pVwQXwPhdQ3yRnUAtOOw+OEqxkr/NNwoD1xTDKXJYIFG4o7rg2yvF5BCly4txXf1jPEpMAbjFc0tzorFq/D7+qY2Eno1HmVzg7PfchDyys2Ji");
|
|
|
- System.out.println(string);
|
|
|
- string = DataEncryptionUtil.decryptRSAByPrivateKey("Jnj84d14EmSgKEXyAbSH+bratWGkpV89/VA5Er4yQOt7qlnKtGYJzBVJNNYMBdmSlW0G+nqDHMhJQcmHrwbjjChYuGeDcmKSRmvFQ9u7LwqmgEfazzKKoVawXmJ40dMsec2yaFyNnCM92xn1hzHvle5BL7x3kza2htGm+iOqO7Y=");
|
|
|
- System.out.println(string);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void encryptBase64() {
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void decryptBase64() {
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void signatureSHA() {
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void verifySHA() {
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void signatureMD5() {
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void verifyMD5() {
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void encryptRSAByPublicKey() {
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void decryptRSAByPrivateKey() {
|
|
|
- }
|
|
|
|
|
|
- @Test
|
|
|
- void encryptDES() throws Exception {
|
|
|
- String helloWorld = DataEncryptionUtil.encryptDES("HELLO WORLD", "12345678");
|
|
|
- System.out.println(helloWorld);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void decryptDES() throws Exception {
|
|
|
- String helloWorld = DataEncryptionUtil.decryptDES("+dhTwlyrdA35S/6Xk5R+yQ==", "12345678");
|
|
|
- System.out.println(helloWorld);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void encryptAES() throws Exception {
|
|
|
- System.out.println(DataEncryptionUtil.publicKeyStr);
|
|
|
- String helloWorld = DataEncryptionUtil.encryptRSAByPublicKey("HELLO WORLD");
|
|
|
- System.out.println(helloWorld);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void decryptAES() throws Exception {
|
|
|
- String data = DataEncryptionUtil.decryptRSAByPrivateKey("a4xjClMUhHo/X4vQoZRJPepvIzKIdiAvcYtcfo/zaFXk86OaABWwCO7gyrrsgPlfMAaXiFxPqxwVZwVCwpwnZv+CM/aSz4cE2NRbiMhUyvV1mng8Zf4D2jpVsKNDipEzhbjPQ7H14+Sitwxxj3JkF8hZlqf7zAgPRSBVfHnc2us=");
|
|
|
- System.out.println(data);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void encrypt3DES() throws Exception {
|
|
|
- String key = "123456781234567812345678";
|
|
|
-// while (key.length()<128){
|
|
|
-// key += UUID.randomUUID().toString().replaceAll("-","");
|
|
|
-// }
|
|
|
-// key = key.substring(0,128);
|
|
|
- System.out.println(key);
|
|
|
-
|
|
|
- String helloWorld = DataEncryptionUtil.encrypt3DES("HELLO WORLD", "123456781234567812345678");
|
|
|
- System.out.println(helloWorld);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void decrypt3DES() throws Exception {
|
|
|
- String helloWorld = DataEncryptionUtil.decrypt3DES("+dhTwlyrdA35S/6Xk5R+yQ==", "123456781234567812345678");
|
|
|
- System.out.println(helloWorld);
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- void encryptByPublicKey() {
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void decryptByPrivateKey() {
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void encryptByPrivateKey() {
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void decryptByPublicKey() {
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void sign() {
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void verify() {
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void enc() throws Exception {
|
|
|
- String string = DataEncryptionUtil.encryptRSAByPublicKey("123!@#QWEqwe");
|
|
|
- System.out.println(string);
|
|
|
- string = DataEncryptionUtil.encryptRSAByPublicKey("123!@#QWEqwe");
|
|
|
- System.out.println(string);
|
|
|
- string = DataEncryptionUtil.encryptRSAByPublicKey("123!@#QWEqwe");
|
|
|
- System.out.println(string);
|
|
|
- string = DataEncryptionUtil.encryptRSAByPublicKey("123!@#QWEqwe");
|
|
|
- System.out.println(string);
|
|
|
- string = DataEncryptionUtil.encryptRSAByPublicKey("123!@#QWEqwe");
|
|
|
- System.out.println(string);
|
|
|
- string = DataEncryptionUtil.encryptRSAByPublicKey("123!@#QWEqwe");
|
|
|
- System.out.println(string);
|
|
|
- }
|
|
|
}
|