fix: RSA解密处理null问题
This commit is contained in:
parent
8f3dc0b489
commit
8768197f40
|
@ -1,6 +1,7 @@
|
||||||
package io.metersphere.sdk.util;
|
package io.metersphere.sdk.util;
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -177,7 +178,11 @@ public class RsaUtils {
|
||||||
try {
|
try {
|
||||||
Cipher cipher = Cipher.getInstance(RSA_ALGORITHM);
|
Cipher cipher = Cipher.getInstance(RSA_ALGORITHM);
|
||||||
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||||
return new String(rsaSplitCodec(cipher, Cipher.DECRYPT_MODE, Base64.decodeBase64(cipherText), privateKey.getModulus().bitLength()), CHARSET);
|
String v = new String(rsaSplitCodec(cipher, Cipher.DECRYPT_MODE, Base64.decodeBase64(cipherText), privateKey.getModulus().bitLength()), CHARSET);
|
||||||
|
if (StringUtils.isBlank(v)) {
|
||||||
|
return cipherText;
|
||||||
|
}
|
||||||
|
return v;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("解密字符串[" + cipherText + "]时遇到异常", e);
|
throw new RuntimeException("解密字符串[" + cipherText + "]时遇到异常", e);
|
||||||
}
|
}
|
||||||
|
@ -198,7 +203,11 @@ public class RsaUtils {
|
||||||
try {
|
try {
|
||||||
Cipher cipher = Cipher.getInstance(RSA_ALGORITHM);
|
Cipher cipher = Cipher.getInstance(RSA_ALGORITHM);
|
||||||
cipher.init(Cipher.DECRYPT_MODE, publicKey);
|
cipher.init(Cipher.DECRYPT_MODE, publicKey);
|
||||||
return new String(rsaSplitCodec(cipher, Cipher.DECRYPT_MODE, Base64.decodeBase64(cipherText), publicKey.getModulus().bitLength()), CHARSET);
|
String v = new String(rsaSplitCodec(cipher, Cipher.DECRYPT_MODE, Base64.decodeBase64(cipherText), publicKey.getModulus().bitLength()), CHARSET);
|
||||||
|
if (StringUtils.isBlank(v)) {
|
||||||
|
return cipherText;
|
||||||
|
}
|
||||||
|
return v;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("解密字符串[" + cipherText + "]时遇到异常", e);
|
throw new RuntimeException("解密字符串[" + cipherText + "]时遇到异常", e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue