...
Code Block | ||
---|---|---|
| ||
public final class Password {
private void setPassword(byte[] pass) throws Exception {
 bytes[] encrypted = encrypt(pass); //arbitrary encryption scheme
clearArray(pass); Â Â
saveBytes(encrypted,"credentials.pw"); //encrypted password to credentials.pw
}
private boolean checkPassword(byte[] pass) throws Exception {
boolean arrays_equal;
byte[] encrypted = loadBytes("credentials.pw"); //load the encrypted password
byte[] decrypted = decrypt(encrypted);
arrays_equal = Arrays.equal(decrypted, pass);
clearArray(decrypted);
clearArray(pass);
return arrays_equal;
}
private clearArray(byte[] a) {
//set all of the elements in a to zero
}
}
|
...