Skip to content

Commit

Permalink
Fix java.lang.NoClassDefFoundError to encrypt_password.sh wgzhao#689
Browse files Browse the repository at this point in the history
  • Loading branch information
wgzhao committed Nov 4, 2022
1 parent 9d88756 commit e496b57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/bin/encrypt_password.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e496b57

Please sign in to comment.