Java从属性文件yaml中存储和读取字节数组

Chr*_*007 4 java arrays spring yaml

我正在开发一个从数据库读取数据的应用程序。数据库中已经存在加密条目。我有字节数组形式的密钥,并希望从 yaml 文件加载它。

有没有办法可以像这样填充数组

private static final byte[] iv = { 13, -11, -88, 20, -110, 113, -2, -8, -15, -99, -23, -10, -10, -74, 1, 11 }
Run Code Online (Sandbox Code Playgroud)

直接来自 yaml 文件?

yaml 文件:

iv: 13,-11,-88
Run Code Online (Sandbox Code Playgroud)

由于我无法自动装配需要使用密钥的类,因此我无法使用 @value 注释(根据我的理解)。所以我想使用像这样的 util 类:

public static byte[] getKeyFor(Class type) {
    return context.getEnvironment().getProperty("iv");
}
Run Code Online (Sandbox Code Playgroud)

Adi*_*xit 5

下面应该可以工作:

application.yml:

iv: 12,32,12,32
Run Code Online (Sandbox Code Playgroud)

在您想要值的类中,将其绑定如下:

@Value("${iv}") byte[] iv;
Run Code Online (Sandbox Code Playgroud)