public String getPublicKey() { for (Map.Entry<String, PublicKey> entry : keyProvider.getPublicKeys().entrySet()) { try { return SshKeyGen.writePublicKey(entry.getValue()); } catch (Exception e) { log.error("getPublicKey: Failed to write PEM", e); } } return null; }
public String getPublicKey() { for (Map.Entry<String, PublicKey> entry : keyProvider.getPublicKeys().entrySet()) { try { return SshKeyGen.writePublicKey(entry.getValue()); } catch (Exception e) { log.error("getPublicKey: Failed to write PEM", e); } } return null; }
@Override public String decrypt(long accountId, String value) throws Exception { RSAPrivateKeyHolder holder = rsaKeyProvider.getPrivateKey(); PublicKey publicKey = rsaKeyProvider.getPublicKeys().get(holder.getKeyId()); String encoded = SshKeyGen.toPEM(publicKey); Map<String, Object> input = jsonMapper.readValue(value); input.put("rewrapKey", encoded); String encrypted = Request.Post(SECRETS_URL.get() + REWRAP) .bodyString(jsonMapper.writeValueAsString(input), ContentType.APPLICATION_JSON) .execute().handleResponse(new ResponseHandler<String>() { @Override public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 300) { throw new IOException("Failed to rewrap secret :" + response.getStatusLine().getReasonPhrase()); } return IOUtils.toString(response.getEntity().getContent()); } }); return unwrap(holder.getKey(), encrypted); }