EncryptedValue { public static EncryptedValue fromString(String value) { if (!value.startsWith(PREFIX)) { throw new IllegalArgumentException("Missing \"enc:\" prefix: " + value); } String suffix = value.substring(PREFIX.length()); byte[] bytes = BaseEncoding.base64().decode(suffix); try { return MAPPER.readValue(bytes, EncryptedValue.class); } catch (IOException e) { return ImmutableLegacyEncryptedValue.of(bytes); } }  @JsonIgnore abstract T accept(EncryptedValueVisitor<T> visitor); @JsonIgnore abstract String decrypt(KeyWithType kwa); static boolean isEncryptedValue(String value); static EncryptedValue fromString(String value); @Override final String toString();  }
@Test(expected = IllegalArgumentException.class) public void weFailToConstructWithInvalidPrefix() { String invalid = "anc:TCkE/OT7xsKWqP4SRNBEj54Pk7wDMQzMGJtX90toFuGeejM/LQBDTZ8hEaKQt/3i"; EncryptedValue.fromString(invalid); }
@Test(expected = IllegalArgumentException.class) public void weFailToConstructWithAnInvalidEncryptedValue() { String invalid = "enc:verysecret^^"; EncryptedValue.fromString(invalid); }