@Test public void testDecrypt() throws Exception { String expected = "abc123"; KeyStore keyStore = KeyStore.of("src/test/resources/account-ecosystem/metadata-local.json", false); String encrypted = encryptWithTestPublicKey(expected); String actual = DecryptAetIdentifiers.decrypt(keyStore, TextNode.valueOf(encrypted)) .textValue(); assertEquals(expected, actual); }
public static JsonNode decrypt(KeyStore keyStore, JsonNode anonIdNode) throws JoseException, KeyNotFoundException { if (anonIdNode.isTextual()) { String anonId = anonIdNode.textValue(); JsonWebStructure fromCompact = JsonWebEncryption.fromCompactSerialization(anonId); String keyId = fromCompact.getKeyIdHeaderValue(); PrivateKey key = keyStore.getKeyOrThrow(keyId); JsonWebEncryption jwe = new JsonWebEncryption(); jwe.setKey(key); jwe.setContentEncryptionKey(key.getEncoded()); jwe.setCompactSerialization(anonId); return TextNode.valueOf(jwe.getPlaintextString()); } else if (anonIdNode.isArray()) { ArrayNode userIds = Json.createArrayNode(); for (JsonNode node : anonIdNode) { userIds.add(decrypt(keyStore, node)); } return userIds; } else if (anonIdNode.isNull()) { return NullNode.getInstance(); } else { throw new IllegalArgumentException( "Argument to decrypt must be a TextNode or ArrayNode, but got " + anonIdNode); } }
DecryptAetIdentifiers extends
    PTransform<PCollection<PubsubMessage>, Result<PCollection<PubsubMessage>, PubsubMessage>> { public static JsonNode decrypt(KeyStore keyStore, JsonNode anonIdNode) throws JoseException, KeyNotFoundException { if (anonIdNode.isTextual()) { String anonId = anonIdNode.textValue(); JsonWebStructure fromCompact = JsonWebEncryption.fromCompactSerialization(anonId); String keyId = fromCompact.getKeyIdHeaderValue(); PrivateKey key = keyStore.getKeyOrThrow(keyId); JsonWebEncryption jwe = new JsonWebEncryption(); jwe.setKey(key); jwe.setContentEncryptionKey(key.getEncoded()); jwe.setCompactSerialization(anonId); return TextNode.valueOf(jwe.getPlaintextString()); } else if (anonIdNode.isArray()) { ArrayNode userIds = Json.createArrayNode(); for (JsonNode node : anonIdNode) { userIds.add(decrypt(keyStore, node)); } return userIds; } else if (anonIdNode.isNull()) { return NullNode.getInstance(); } else { throw new IllegalArgumentException( "Argument to decrypt must be a TextNode or ArrayNode, but got " + anonIdNode); } } }
DecryptAetIdentifiers extends
    PTransform<PCollection<PubsubMessage>, Result<PCollection<PubsubMessage>, PubsubMessage>> { public static JsonNode decrypt(KeyStore keyStore, JsonNode anonIdNode) throws JoseException, KeyNotFoundException { if (anonIdNode.isTextual()) { String anonId = anonIdNode.textValue(); JsonWebStructure fromCompact = JsonWebEncryption.fromCompactSerialization(anonId); String keyId = fromCompact.getKeyIdHeaderValue(); PrivateKey key = keyStore.getKeyOrThrow(keyId); JsonWebEncryption jwe = new JsonWebEncryption(); jwe.setKey(key); jwe.setContentEncryptionKey(key.getEncoded()); jwe.setCompactSerialization(anonId); return TextNode.valueOf(jwe.getPlaintextString()); } else if (anonIdNode.isArray()) { ArrayNode userIds = Json.createArrayNode(); for (JsonNode node : anonIdNode) { userIds.add(decrypt(keyStore, node)); } return userIds; } else if (anonIdNode.isNull()) { return NullNode.getInstance(); } else { throw new IllegalArgumentException( "Argument to decrypt must be a TextNode or ArrayNode, but got " + anonIdNode); } } private  DecryptAetIdentifiers(ValueProvider<String> schemasLocation,
      ValueProvider<String> metadataLocation, ValueProvider<Boolean> kmsEnabled); }
DecryptAetIdentifiers extends
    PTransform<PCollection<PubsubMessage>, Result<PCollection<PubsubMessage>, PubsubMessage>> { public static JsonNode decrypt(KeyStore keyStore, JsonNode anonIdNode) throws JoseException, KeyNotFoundException { if (anonIdNode.isTextual()) { String anonId = anonIdNode.textValue(); JsonWebStructure fromCompact = JsonWebEncryption.fromCompactSerialization(anonId); String keyId = fromCompact.getKeyIdHeaderValue(); PrivateKey key = keyStore.getKeyOrThrow(keyId); JsonWebEncryption jwe = new JsonWebEncryption(); jwe.setKey(key); jwe.setContentEncryptionKey(key.getEncoded()); jwe.setCompactSerialization(anonId); return TextNode.valueOf(jwe.getPlaintextString()); } else if (anonIdNode.isArray()) { ArrayNode userIds = Json.createArrayNode(); for (JsonNode node : anonIdNode) { userIds.add(decrypt(keyStore, node)); } return userIds; } else if (anonIdNode.isNull()) { return NullNode.getInstance(); } else { throw new IllegalArgumentException( "Argument to decrypt must be a TextNode or ArrayNode, but got " + anonIdNode); } } private  DecryptAetIdentifiers(ValueProvider<String> schemasLocation,
      ValueProvider<String> metadataLocation, ValueProvider<Boolean> kmsEnabled); static DecryptAetIdentifiers of(ValueProvider<String> schemasLocation,
      ValueProvider<String> metadataLocation, ValueProvider<Boolean> kmsEnabled); @Override Result<PCollection<PubsubMessage>, PubsubMessage> expand(
      PCollection<PubsubMessage> messages); static JsonNode decrypt(KeyStore keyStore, JsonNode anonIdNode); }
DecryptAetIdentifiers extends
    PTransform<PCollection<PubsubMessage>, Result<PCollection<PubsubMessage>, PubsubMessage>> { public static JsonNode decrypt(KeyStore keyStore, JsonNode anonIdNode) throws JoseException, KeyNotFoundException { if (anonIdNode.isTextual()) { String anonId = anonIdNode.textValue(); JsonWebStructure fromCompact = JsonWebEncryption.fromCompactSerialization(anonId); String keyId = fromCompact.getKeyIdHeaderValue(); PrivateKey key = keyStore.getKeyOrThrow(keyId); JsonWebEncryption jwe = new JsonWebEncryption(); jwe.setKey(key); jwe.setContentEncryptionKey(key.getEncoded()); jwe.setCompactSerialization(anonId); return TextNode.valueOf(jwe.getPlaintextString()); } else if (anonIdNode.isArray()) { ArrayNode userIds = Json.createArrayNode(); for (JsonNode node : anonIdNode) { userIds.add(decrypt(keyStore, node)); } return userIds; } else if (anonIdNode.isNull()) { return NullNode.getInstance(); } else { throw new IllegalArgumentException( "Argument to decrypt must be a TextNode or ArrayNode, but got " + anonIdNode); } } private  DecryptAetIdentifiers(ValueProvider<String> schemasLocation,
      ValueProvider<String> metadataLocation, ValueProvider<Boolean> kmsEnabled); static DecryptAetIdentifiers of(ValueProvider<String> schemasLocation,
      ValueProvider<String> metadataLocation, ValueProvider<Boolean> kmsEnabled); @Override Result<PCollection<PubsubMessage>, PubsubMessage> expand(
      PCollection<PubsubMessage> messages); static JsonNode decrypt(KeyStore keyStore, JsonNode anonIdNode); static final String ACCOUNT_ECOSYSTEM; }