Skip to content

Instantly share code, notes, and snippets.

@d0nutptr
Created August 1, 2017 01:28
Show Gist options
  • Save d0nutptr/493771425dd65c7a3b1f188aa4fcf4f4 to your computer and use it in GitHub Desktop.
Save d0nutptr/493771425dd65c7a3b1f188aa4fcf4f4 to your computer and use it in GitHub Desktop.
//transforms into PBKDF2-HMAC-SHA-256.
AndroidConceal.get().nativeLibrary.ensureCryptoLoaded();
PBKDF2Hybrid encryptionKeyGenerator = new PBKDF2Hybrid();
encryptionKeyGenerator.setIterations(KEY_DERIVATION_ROUNDS);
encryptionKeyGenerator.setSalt(encryptionSalt, 0, encryptionSalt.length);
encryptionKeyGenerator.setKeyLengthInBytes(ENC_KEY_SIZE);
encryptionKeyGenerator.setPassword(passwordBytes, 0, passwordBytes.length);
encryptionKeySecret = encryptionKeyGenerator.generate();
PBKDF2Hybrid authenticationKeyGenerator = new PBKDF2Hybrid();
authenticationKeyGenerator.setIterations(KEY_DERIVATION_ROUNDS);
authenticationKeyGenerator.setSalt(authenticationSalt, 0, authenticationSalt.length);
authenticationKeyGenerator.setKeyLengthInBytes(ENC_KEY_SIZE);
authenticationKeyGenerator.setPassword(encryptionKeySecret, 0, encryptionKeySecret.length);
authenticationKeySecret = authenticationKeyGenerator.generate();
SecretKey encKey = new SecretKeySpec(encryptionKeySecret, 0, encryptionKeySecret.length, "AES");
SecretKey authKey = new SecretKeySpec(authenticationKeySecret, 0, authenticationKeySecret.length, "AES");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment