diff --git a/common/src/main/java/com/wgzhao/addax/common/util/EncryptUtil.java b/common/src/main/java/com/wgzhao/addax/common/util/EncryptUtil.java index 22abc08df..c6ed3ac36 100644 --- a/common/src/main/java/com/wgzhao/addax/common/util/EncryptUtil.java +++ b/common/src/main/java/com/wgzhao/addax/common/util/EncryptUtil.java @@ -34,6 +34,7 @@ import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.SecretKeySpec; @@ -74,7 +75,8 @@ public class EncryptUtil public static String encrypt(String password) { try { - pbeCipher.init(Cipher.ENCRYPT_MODE, secSpec, ivSpec); + GCMParameterSpec params = new GCMParameterSpec(128, ivSpec.getIV(), 0, 12); + pbeCipher.init(Cipher.ENCRYPT_MODE, secSpec, params); byte[] cryptoText = pbeCipher.doFinal(password.getBytes(StandardCharsets.UTF_8)); return base64Encode(cryptoText); } @@ -91,7 +93,8 @@ private static String base64Encode(byte[] bytes) public static String decrypt(String encrypted) { try { - pbeCipher.init(Cipher.DECRYPT_MODE, secSpec, ivSpec); + GCMParameterSpec params = new GCMParameterSpec(128, ivSpec.getIV(), 0, 12); + pbeCipher.init(Cipher.DECRYPT_MODE, secSpec, params); return new String(pbeCipher.doFinal(base64Decode(encrypted)), StandardCharsets.UTF_8); } catch (Exception e) { diff --git a/core/src/main/bin/encrypt_password.sh b/core/src/main/bin/encrypt_password.sh index fcdb71ad2..c7f3c1ef5 100644 --- a/core/src/main/bin/encrypt_password.sh +++ b/core/src/main/bin/encrypt_password.sh @@ -30,4 +30,11 @@ if [ $# -ne 1 ]; then exit 1 fi -java -cp ${ADDAX_HOME}/lib/addax-common-*.jar com.wgzhao.addax.common.util.EncryptUtil $1 +cd ${ADDAX_HOME} +commjar=$(ls lib/addax-common-*.jar lib/slf4j-*.jar lib/logback*.jar |tr '\t' ':') +for jar in ${commjar[@]} +do + classpath=${classpath}:$jar +done +java -cp $classpath com.wgzhao.addax.common.util.EncryptUtil $1 +#java -cp ${ADDAX_HOME}/lib/addax-common-*.jar:${ADDAX_HOME}/lib/slf4j-api-*.jar com.wgzhao.addax.common.util.EncryptUtil $1