Last active
November 25, 2021 11:01
-
-
Save Jaymo/c2a4b6f29b8c064d4b57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final int PBE_ITERATION_COUNT = 10000; //Am not sure on this size and low end devices. I should test more to prevent lag | |
private static final String PBE_ALGORITHM = "PBKDF2WithHmacSHA1"; | |
public static final String PROVIDER = "BC"; | |
private static final String SECRET_KEY_ALGORITHM = "AES/GCM/NoPadding; | |
public static SecretKey getSecretKey(String password, String salt) throws CryptoException { | |
try { | |
PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray(), Util.HexEncoder.toByte(salt), PBE_ITERATION_COUNT, 256); | |
SecretKeyFactory factory = SecretKeyFactory.getInstance(PBE_ALGORITHM, PROVIDER); | |
SecretKey tmp = factory.generateSecret(pbeKeySpec); | |
SecretKey secret = new SecretKeySpec(tmp.getEncoded(), SECRET_KEY_ALGORITHM); | |
return secret; | |
} catch (Exception e) { | |
throw new CryptoException("Unable to get secret key", e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment