@Test public void testMasterKey() { CardKeysProvider p = new PlaintextKeysProvider(); Assert.assertTrue(p.getCardKeys("404142434445464748494a4b4c4d4e4f").isPresent()); }
@Override public Optional<GPCardKeys> getCardKeys(String spec) { if (spec == null) return Optional.empty(); if ("default".startsWith(spec.toLowerCase())) return Optional.of(PlaintextKeys.defaultKey()); try { for (PlaintextKeys.Diversification d : PlaintextKeys.Diversification.values()) { if (spec.toLowerCase().startsWith(d.name().toLowerCase())) { byte[] k = HexUtils.stringToBin(spec.substring(d.name().length() + 1)); return Optional.of(PlaintextKeys.derivedFromMasterKey(k, null, d)); } } byte[] k = HexUtils.stringToBin(spec); return Optional.of(PlaintextKeys.fromMasterKey(k)); } catch (IllegalArgumentException e) { } return Optional.empty(); }
PlaintextKeysProvider implements CardKeysProvider { @Override public Optional<GPCardKeys> getCardKeys(String spec) { if (spec == null) return Optional.empty(); if ("default".startsWith(spec.toLowerCase())) return Optional.of(PlaintextKeys.defaultKey()); try { for (PlaintextKeys.Diversification d : PlaintextKeys.Diversification.values()) { if (spec.toLowerCase().startsWith(d.name().toLowerCase())) { byte[] k = HexUtils.stringToBin(spec.substring(d.name().length() + 1)); return Optional.of(PlaintextKeys.derivedFromMasterKey(k, null, d)); } } byte[] k = HexUtils.stringToBin(spec); return Optional.of(PlaintextKeys.fromMasterKey(k)); } catch (IllegalArgumentException e) { } return Optional.empty(); } }
PlaintextKeysProvider implements CardKeysProvider { @Override public Optional<GPCardKeys> getCardKeys(String spec) { if (spec == null) return Optional.empty(); if ("default".startsWith(spec.toLowerCase())) return Optional.of(PlaintextKeys.defaultKey()); try { for (PlaintextKeys.Diversification d : PlaintextKeys.Diversification.values()) { if (spec.toLowerCase().startsWith(d.name().toLowerCase())) { byte[] k = HexUtils.stringToBin(spec.substring(d.name().length() + 1)); return Optional.of(PlaintextKeys.derivedFromMasterKey(k, null, d)); } } byte[] k = HexUtils.stringToBin(spec); return Optional.of(PlaintextKeys.fromMasterKey(k)); } catch (IllegalArgumentException e) { } return Optional.empty(); } PlaintextKeysProvider(); }
PlaintextKeysProvider implements CardKeysProvider { @Override public Optional<GPCardKeys> getCardKeys(String spec) { if (spec == null) return Optional.empty(); if ("default".startsWith(spec.toLowerCase())) return Optional.of(PlaintextKeys.defaultKey()); try { for (PlaintextKeys.Diversification d : PlaintextKeys.Diversification.values()) { if (spec.toLowerCase().startsWith(d.name().toLowerCase())) { byte[] k = HexUtils.stringToBin(spec.substring(d.name().length() + 1)); return Optional.of(PlaintextKeys.derivedFromMasterKey(k, null, d)); } } byte[] k = HexUtils.stringToBin(spec); return Optional.of(PlaintextKeys.fromMasterKey(k)); } catch (IllegalArgumentException e) { } return Optional.empty(); } PlaintextKeysProvider(); @Override Optional<GPCardKeys> getCardKeys(String spec); }
PlaintextKeysProvider implements CardKeysProvider { @Override public Optional<GPCardKeys> getCardKeys(String spec) { if (spec == null) return Optional.empty(); if ("default".startsWith(spec.toLowerCase())) return Optional.of(PlaintextKeys.defaultKey()); try { for (PlaintextKeys.Diversification d : PlaintextKeys.Diversification.values()) { if (spec.toLowerCase().startsWith(d.name().toLowerCase())) { byte[] k = HexUtils.stringToBin(spec.substring(d.name().length() + 1)); return Optional.of(PlaintextKeys.derivedFromMasterKey(k, null, d)); } } byte[] k = HexUtils.stringToBin(spec); return Optional.of(PlaintextKeys.fromMasterKey(k)); } catch (IllegalArgumentException e) { } return Optional.empty(); } PlaintextKeysProvider(); @Override Optional<GPCardKeys> getCardKeys(String spec);  }