Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting and retrieving credentials do not work anymore on Android devices. #113

Open
azemlyankin10 opened this issue Sep 19, 2024 · 1 comment

Comments

@azemlyankin10
Copy link

While setting or retrieving credentials using build-in methods throws an error. So I found a solution for myself using the Capasitor-Secure-Store plugin to keep my username and password there.

@tesplugNaN
Copy link

tesplugNaN commented Sep 26, 2024

@azemlyankin10
You can modify 2 methods for Android

` @SuppressLint("NewAPI") // API level is already checked
private Key generateKey(String KEY_ALIAS) throws GeneralSecurityException, IOException {
Key key = generateKey(KEY_ALIAS, true);

    if (key == null) {
        key = generateKey(KEY_ALIAS, false);
    }

    return key;
}
private Key generateKey(String KEY_ALIAS, boolean isStrongBoxBacked) throws GeneralSecurityException, IOException, StrongBoxUnavailableException {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            KeyGenerator generator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, ANDROID_KEY_STORE);
            KeyGenParameterSpec.Builder paramBuilder = new KeyGenParameterSpec.Builder(KEY_ALIAS, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
                    .setBlockModes(KeyProperties.BLOCK_MODE_GCM)
                    .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
                    .setRandomizedEncryptionRequired(false);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                paramBuilder.setUnlockedDeviceRequired(true);
                paramBuilder.setIsStrongBoxBacked(isStrongBoxBacked);
            }

            generator.init(paramBuilder.build());
            return generator.generateKey();
        } else {
            return getAESKey(KEY_ALIAS);
        }
    } catch (Exception e) {
        return null;
    }
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants