@Test public void saveAndRetrieveSecretKey() throws IOException, ClassNotFoundException { SecretKey sK = SensitiveDataCryptoUtils.buildSecretKey(SECRETKEY_LENGTH, configuration.getPbkdf2Algorithm()); String secretKeyFingerPrint = Base64.getEncoder().encodeToString(sK.getEncoded()); File keyFile = File.createTempFile("keyfile", "key"); keyFile.deleteOnExit(); saveInFile(keyFile, sK); ObjectInputStream ois = new ObjectInputStream(new FileInputStream(keyFile)); SecretKey readKey = (SecretKey) ois.readObject(); ois.close(); assertTrue(readKey.getEncoded().length * 8 == SECRETKEY_LENGTH); assertTrue(Base64.getEncoder().encodeToString(readKey.getEncoded()).equals(secretKeyFingerPrint)); }
public static SecretKey buildSecretKey(byte[] keyBytes, String algo) { return new SecretKeySpec(keyBytes, algo); }
SensitiveDataCryptoUtils { public static SecretKey buildSecretKey(byte[] keyBytes, String algo) { return new SecretKeySpec(keyBytes, algo); } }
SensitiveDataCryptoUtils { public static SecretKey buildSecretKey(byte[] keyBytes, String algo) { return new SecretKeySpec(keyBytes, algo); } private  SensitiveDataCryptoUtils(); }
SensitiveDataCryptoUtils { public static SecretKey buildSecretKey(byte[] keyBytes, String algo) { return new SecretKeySpec(keyBytes, algo); } private  SensitiveDataCryptoUtils(); static synchronized void configure(SensitiveDataCryptoUtilsConfiguration configuration); static SecretKey buildSecretKey(byte[] keyBytes, String algo); static SecretKey buildSecretKey(int lengthInBits, String algo); static String buildMACAsBase64String(String input); static String buildSaltedMACAsBase64String(String input); static byte[] buildMAC(String input); static byte[] buildMAC(String input, byte[] salt); static byte[] buildMAC(byte[] input, byte[] salt); static boolean verifyMAC(String message, String macAsBase64); static boolean verifySaltedMAC(String message, String macAndSaltAsBase64); static String encryptAsBase64String(Integer input); static String encryptAsBase64String(Long input); static String encryptAsBase64String(String input); static byte[] encrypt(String input); static byte[] encrypt(byte[] input); static Long decryptAsLong(String base64Input); static Long decryptAsLong(byte[] input); static String decryptAsString(String base64Input); static String decryptAsString(byte[] input); static byte[] decrypt(byte[] input); static byte[] sealObject(Serializable object); static Object unsealObject(byte[] encryptedObject); static String generateStrongPasswordHash(char[] password); static boolean validateStrongPasswordHash(char[] passwd, String storedHash); }
SensitiveDataCryptoUtils { public static SecretKey buildSecretKey(byte[] keyBytes, String algo) { return new SecretKeySpec(keyBytes, algo); } private  SensitiveDataCryptoUtils(); static synchronized void configure(SensitiveDataCryptoUtilsConfiguration configuration); static SecretKey buildSecretKey(byte[] keyBytes, String algo); static SecretKey buildSecretKey(int lengthInBits, String algo); static String buildMACAsBase64String(String input); static String buildSaltedMACAsBase64String(String input); static byte[] buildMAC(String input); static byte[] buildMAC(String input, byte[] salt); static byte[] buildMAC(byte[] input, byte[] salt); static boolean verifyMAC(String message, String macAsBase64); static boolean verifySaltedMAC(String message, String macAndSaltAsBase64); static String encryptAsBase64String(Integer input); static String encryptAsBase64String(Long input); static String encryptAsBase64String(String input); static byte[] encrypt(String input); static byte[] encrypt(byte[] input); static Long decryptAsLong(String base64Input); static Long decryptAsLong(byte[] input); static String decryptAsString(String base64Input); static String decryptAsString(byte[] input); static byte[] decrypt(byte[] input); static byte[] sealObject(Serializable object); static Object unsealObject(byte[] encryptedObject); static String generateStrongPasswordHash(char[] password); static boolean validateStrongPasswordHash(char[] passwd, String storedHash); static final Charset ENCRYPTION_CHARSET; }