新增密码传输解密服务
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.ruoyi.framework.web.service;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
|
||||
@Service
|
||||
public class PasswordTransferCryptoService
|
||||
{
|
||||
@Value("${security.password-transfer.key}")
|
||||
private String key;
|
||||
|
||||
public String decrypt(String cipherText)
|
||||
{
|
||||
try
|
||||
{
|
||||
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES"));
|
||||
return new String(cipher.doFinal(Base64.getDecoder().decode(cipherText)), StandardCharsets.UTF_8);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new ServiceException("密码解密失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user