@Test public void testGetKeyFromFile() throws Exception { byte[] bytes = new byte[32]; SecureRandom random = new SecureRandom(); random.nextBytes(bytes); EncryptionUtils.saveKeyToFile("James", bytes); byte[] gotten = EncryptionUtils.getKeyFromFile("James"); Assert.assertArrayEquals(bytes, gotten); for (int i = 0; i < 10; i++){ String key = new BigInteger(130, random).toString(32); random.nextBytes(bytes); EncryptionUtils.saveKeyToFile(key, bytes); Assert.assertArrayEquals(EncryptionUtils.getKeyFromFile(key), bytes); } }
public static byte[] getKeyFromFile(String propertyName) throws DecoderException { if (StringUtils.isBlank(propertyName)) { return null; } Properties keyStore = getKey(); if (keyStore == null) { return null; } if (keyStore.get(propertyName) != null){ String value = keyStore.get(propertyName).toString(); return Hex.decodeHex(value.toCharArray()); } return null; }
EncryptionUtils { public static byte[] getKeyFromFile(String propertyName) throws DecoderException { if (StringUtils.isBlank(propertyName)) { return null; } Properties keyStore = getKey(); if (keyStore == null) { return null; } if (keyStore.get(propertyName) != null){ String value = keyStore.get(propertyName).toString(); return Hex.decodeHex(value.toCharArray()); } return null; } }
EncryptionUtils { public static byte[] getKeyFromFile(String propertyName) throws DecoderException { if (StringUtils.isBlank(propertyName)) { return null; } Properties keyStore = getKey(); if (keyStore == null) { return null; } if (keyStore.get(propertyName) != null){ String value = keyStore.get(propertyName).toString(); return Hex.decodeHex(value.toCharArray()); } return null; }  }
EncryptionUtils { public static byte[] getKeyFromFile(String propertyName) throws DecoderException { if (StringUtils.isBlank(propertyName)) { return null; } Properties keyStore = getKey(); if (keyStore == null) { return null; } if (keyStore.get(propertyName) != null){ String value = keyStore.get(propertyName).toString(); return Hex.decodeHex(value.toCharArray()); } return null; }  static boolean isEqual(String aa, String bb); static byte[] getKeyFromFile(String propertyName); static synchronized void saveKeyToFile(String key, byte[] value); }
EncryptionUtils { public static byte[] getKeyFromFile(String propertyName) throws DecoderException { if (StringUtils.isBlank(propertyName)) { return null; } Properties keyStore = getKey(); if (keyStore == null) { return null; } if (keyStore.get(propertyName) != null){ String value = keyStore.get(propertyName).toString(); return Hex.decodeHex(value.toCharArray()); } return null; }  static boolean isEqual(String aa, String bb); static byte[] getKeyFromFile(String propertyName); static synchronized void saveKeyToFile(String key, byte[] value);  }