Email integration with PEC and MAILGUN services using api call.
This commit is contained in:
@@ -20,6 +20,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.itextpdf.styledxmlparser.jsoup.Jsoup;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -40,6 +41,10 @@ import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientNotFoundExcep
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientUnauthorizedException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientValidationException;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||
|
||||
|
||||
@@ -467,4 +472,47 @@ public class Utils {
|
||||
|
||||
return sanitizedInput.matches(wholeNumberPattern);
|
||||
}
|
||||
|
||||
public static String encryptCredential(String value) {
|
||||
try {
|
||||
if(Boolean.FALSE.equals(isEmpty(value))) {
|
||||
|
||||
IvParameterSpec iv = new IvParameterSpec(GepafinConstant.ENCRYPT_INIT_VECTOR.getBytes("UTF-8"));
|
||||
SecretKeySpec skeySpec = new SecretKeySpec(Base64.getDecoder().decode(GepafinConstant.ENCRYPT_KEY), "AES");
|
||||
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
|
||||
|
||||
byte[] encrypted = cipher.doFinal(value.getBytes());
|
||||
|
||||
return Base64.getEncoder().encodeToString(encrypted);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
log.error("Exception occured while encrypt credential :- {0}", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String decryptCredential(String encrypted) {
|
||||
try {
|
||||
if(Boolean.FALSE.equals(isEmpty(encrypted))) {
|
||||
|
||||
IvParameterSpec iv = new IvParameterSpec(GepafinConstant.ENCRYPT_INIT_VECTOR.getBytes("UTF-8"));
|
||||
SecretKeySpec skeySpec = new SecretKeySpec(Base64.getDecoder().decode(GepafinConstant.ENCRYPT_KEY), "AES");
|
||||
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
|
||||
|
||||
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
|
||||
|
||||
byte[] original = cipher.doFinal(Base64.getDecoder().decode(encrypted));
|
||||
|
||||
return new String(original);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// log.error("Exception occured while decrypt credential :- {0}", ex);
|
||||
return encrypted;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user