Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
getSecureRawKey
static byte[] getSecureRawKey(String seed) {
/*
* check http://www.motorola.com/sites/motodev/library/using_aes_in_android.html
* for detail information
*/
char[] humanPassphrase = seed.toCharArray();
byte[] salt = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF
}; // must save this!
final int HASH_ITERATIONS = 10000;
final int KEY_LENGTH = 128;
PBEKeySpec mykeyspec = new PBEKeySpec(humanPassphrase, salt, HASH_ITERATIONS, KEY_LENGTH);
SecretKeyFactory keyfactory;
try {
keyfactory = SecretKeyFactory.getInstance("PBEWITHSHAANDTWOFISH-CBC");
SecretKey sk = keyfactory.generateSecret(mykeyspec);
byte[] skAsByteArray = sk.getEncoded();
SecretKey skforAES = new SecretKeySpec(skAsByteArray, "AES");
byte[] raw = skforAES.getEncoded();
return raw;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeySpecException e) {
e.printStackTrace();
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.