方案一:读取出文件的byte[],配置在Apollo里

这里是指把byte[]转化为十六进制字符串保存在Apollo中

把文件转换为byte[]方法有很多,有的文本编辑器可以支持安装插件直接显示出十六进制显示的二进制字符串。
或者读取出byte[]之后调用Hex.encodeHex()即可获得。

之后配置在Apollo,作为变量(值为字符串类型)。
以下是一个文件的示例:
aced0005737200146a6176612e73656375726974792e4b6579526570bdf94fb3889aa5430200044c0009616c676f726974686d7400124c6a6176612f6c616e672f537472696e673b5b0007656e636f6465647400025b424c0006666f726d617471007e00014c00047479706574001b4c6a6176612f73656375726974792f4b657952657024547970653b7870740003525341757200025b42acf317f8060854e00200007870000000a230819f300d06092a864886f70d010101050003818d0030818902818100a3e210b74b09fa0cbe7fb22029c8fcadc9cce7e8366873d3f7d035a7fdb457d683eccb2d89351e08b7a3dd42a6de5f8a6f99d66d8215a226d47e79dfed1e94376c7d15ee1327f6382cc0318ef8501a1ae92ebec6afdda05b18bb4c637ddc02ef32b3e3fc3bee696b75e1ef82c8cb50419eec1f4ea01f6bc1cb7cd92b0fa36c230203010001740005582e3530397e7200196a6176612e73656375726974792e4b6579526570245479706500000000000000001200007872000e6a6176612e6c616e672e456e756d000000000000000012000078707400065055424c4943

读取时,把读到的字符串值通过 Hex.decodeHex(str)转换为byte[]

方案二:把文件通过base64编码,配置在Apollo里

把文件转换为base64编码字符串方法很多,以下是转换好的内容:
rO0ABXNyABRqYXZhLnNlY3VyaXR5LktleVJlcL35T7OImqVDAgAETAAJYWxnb3JpdGhtdAASTGphdmEvbGFuZy9TdHJpbmc7WwAHZW5jb2RlZHQAAltCTAAGZm9ybWF0cQB+AAFMAAR0eXBldAAbTGphdmEvc2VjdXJpdHkvS2V5UmVwJFR5cGU7eHB0AANSU0F1cgACW0Ks8xf4BghU4AIAAHhwAAAAojCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAo+IQt0sJ+gy+f7IgKcj8rcnM5+g2aHPT99A1p/20V9aD7MstiTUeCLej3UKm3l+Kb5nWbYIVoibUfnnf7R6UN2x9Fe4TJ/Y4LMAxjvhQGhrpLr7Gr92gWxi7TGN93ALvMrPj/DvuaWt14e+CyMtQQZ7sH06gH2vBy3zZKw+jbCMCAwEAAXQABVguNTA5fnIAGWphdmEuc2VjdXJpdHkuS2V5UmVwJFR5cGUAAAAAAAAAABIAAHhyAA5qYXZhLmxhbmcuRW51bQAAAAAAAAAAEgAAeHB0AAZQVUJMSUM=

读取时,把base64解码之后获得的就是byte[],解码方式比如:Base64.getDecoder().decode(base64Str)

后续步骤

获得到了byte[]之后一切操作都和在本地直接读取文件类似,如:

InputStream input = new ByteArrayInputStream(解码后获得的byte[]);
ObjectInputStream inputStream = new ObjectInputStream(input);
Object obj = inputStream.readObject();
RSAPublicKey czPublicKey2 = (RSAPublicKey) obj;
byte[] encbyte2 = rsa.encrypt(pass, czPublicKey2);
System.out.println(RSA.toHexString(encbyte2));

标签: none

添加新评论