use of org.bouncycastle.crypto.macs.HMac in project XobotOS by xamarin.
the class JDKKeyStore method engineStore.
public void engineStore(OutputStream stream, char[] password) throws IOException {
DataOutputStream dOut = new DataOutputStream(stream);
byte[] salt = new byte[STORE_SALT_SIZE];
int iterationCount = MIN_ITERATIONS + (random.nextInt() & 0x3ff);
random.nextBytes(salt);
dOut.writeInt(STORE_VERSION);
dOut.writeInt(salt.length);
dOut.write(salt);
dOut.writeInt(iterationCount);
// BEGIN android-changed
HMac hMac = new HMac(new OpenSSLDigest.SHA1());
MacOutputStream mOut = new MacOutputStream(dOut, hMac);
PBEParametersGenerator pbeGen = new PKCS12ParametersGenerator(new OpenSSLDigest.SHA1());
// END android-changed
byte[] passKey = PBEParametersGenerator.PKCS12PasswordToBytes(password);
pbeGen.init(passKey, salt, iterationCount);
hMac.init(pbeGen.generateDerivedMacParameters(hMac.getMacSize()));
for (int i = 0; i != passKey.length; i++) {
passKey[i] = 0;
}
saveStore(mOut);
byte[] mac = new byte[hMac.getMacSize()];
hMac.doFinal(mac, 0);
dOut.write(mac);
dOut.close();
}
Aggregations