/** * Read credential from resource (in a jar, war, ...) * * @see java.lang.ClassLoader#getResourceAsStream(String) */ public T readFromResource(String resourcePath) throws IOException, GeneralSecurityException { try (InputStream in = ClassLoader.getSystemResourceAsStream(resourcePath)) { return decode(in); } }
/** * Decode credential from byte array. */ public T decode(byte[] bytes) throws IOException, GeneralSecurityException { try (ByteArrayInputStream in = new ByteArrayInputStream(bytes)) { return decode(in); } }
/** * Read credential from file */ public T readFromFile(String fileName) throws IOException, GeneralSecurityException { byte[] bytes = Files.readAllBytes(Paths.get(fileName)); return decode(bytes); }
/** * Decode credential from an InputStream. */ public T decode(InputStream in) throws IOException, GeneralSecurityException { try (ByteArrayOutputStream buffer = new ByteArrayOutputStream()) { int nRead; byte[] data = new byte[1024]; while ((nRead = in.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); return decode(buffer.toByteArray()); } } }
try { SecurityInfo securityInfo = SecurityInfo.newRawPublicKeyInfo(endpoint, SecurityUtil.publicKey.decode(value.publicKeyOrId)); return Arrays.asList(securityInfo); } catch (IOException | GeneralSecurityException e) {