我想用aes256加密算法对application.yml进行加密,这样,如果有人想对其进行解密,则需要一个唯一的密钥。 application.yml
security:
TEST:
Host:yummy.com
Port:9000
Password:£-+:_#642
Secure:true
DEV:
Host:ZIM.com
Port:9001
Password:3678&££
Secure:true
//配置类
@ConfigurationProperties(prefix="security")
public class SecurityProperties implements Serializable{
TESTPrpperties;
DEVProperties;
//getter and setter
public static class TESTProperties{
Host;
Port;
Password;
Secure;
//getter and setter
}
public static class DEVProperties{
Host;
Port;
Password;
Secure;
//getter and setter
}
}
现在我们有加密类
@Qualifier
private SecurityProperties devconfig;
public String encryptObj() {
try {
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
KeyGenerator gen = KeyGenerator.getInstance("AES");
gen.init(256);
SecretKey sKey = gen.generateKey();
Cipher c = Cipher.getInstance("AES");
c.init(Cipher.ENCRYPT_MODE,sKey);
SealedObject so = new SealedObject(devconfig,c);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(so);
oos.flush();
System.out.println("SealedObject was written to Object file");
} catch (Exception e) {
System.out.println(e);
}
return null;
成功运行应用程序,我正在邮递员中进行测试,但我没有以邮递员的身份获取加密的application.yml数据,我想以加密形式分别返回特定的加密数据,例如TESTProperties数据和DEVProperty数据。