// Path: app/src/main/java/rehanced/com/simpleetherwallet/interfaces/FingerprintListener.java
// public interface FingerprintListener {
//     public void authenticationFailed(String error);
// 
//     public void authenticationSucceeded(FingerprintManager.AuthenticationResult result);
// }
// 
// Path: app/src/main/java/rehanced/com/simpleetherwallet/utils/AppLockUtils.java
// public class AppLockUtils {
// 
//     public static boolean hasDeviceFingerprintSupport(Context context) {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//             FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
//             if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
//                 return false;
//             }
//             return fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints();
//         } else {
//             return false;
//         }
//     }
// 
// }
// 
// Path: app/src/main/java/rehanced/com/simpleetherwallet/utils/FingerprintHelper.java
// @RequiresApi(api = Build.VERSION_CODES.M)
// public class FingerprintHelper extends FingerprintManager.AuthenticationCallback {
// 
//     private FingerprintListener listener;
// 
//     public FingerprintHelper(FingerprintListener listener) {
//         this.listener = listener;
//     }
// 
//     private CancellationSignal cancellationSignal;
// 
//     public void startAuth(FingerprintManager manager, FingerprintManager.CryptoObject cryptoObject) {
//         cancellationSignal = new CancellationSignal();
// 
//         try {
//             manager.authenticate(cryptoObject, cancellationSignal, 0, this, null);
//         } catch (SecurityException ex) {
//             listener.authenticationFailed("An error occurred:\n" + ex.getMessage());
//         } catch (Exception ex) {
//             listener.authenticationFailed("An error occurred\n" + ex.getMessage());
//         }
//     }
// 
//     public void cancel() {
//         if (cancellationSignal != null)
//             cancellationSignal.cancel();
//     }
// 
//     @Override
//     public void onAuthenticationError(int errMsgId, CharSequence errString) {
//         listener.authenticationFailed(errString.toString());
//     }
// 
//     @Override
//     public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
//         listener.authenticationFailed(helpString.toString());
//     }
// 
//     @Override
//     public void onAuthenticationFailed() {
//         listener.authenticationFailed("Authentication failed");
//     }
// 
//     @Override
//     public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
//         listener.authenticationSucceeded(result);
//     }
// 
// }


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import androidx.annotation.RequiresApi;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
import java.security.KeyStore;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import me.zhanghai.android.patternlock.PatternUtils;
import me.zhanghai.android.patternlock.PatternView;
import rehanced.com.simpleetherwallet.R;
import rehanced.com.simpleetherwallet.interfaces.FingerprintListener;
import rehanced.com.simpleetherwallet.utils.AppLockUtils;
import rehanced.com.simpleetherwallet.utils.FingerprintHelper;
    @RequiresApi(api = Build.VERSION_CODES.M)
    public boolean cipherInit() {
        try {
            cipher = Cipher.getInstance(
                    KeyProperties.KEY_ALGORITHM_AES + "/"
                            + KeyProperties.BLOCK_MODE_CBC + "/"
                            + KeyProperties.ENCRYPTION_PADDING_PKCS7);
        } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
            e.printStackTrace();
        }

        try {
            keyStore.load(null);
            SecretKey key = (SecretKey) keyStore.getKey("Lunary", null);
            cipher.init(Cipher.ENCRYPT_MODE, key);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    protected void generateKey() {
        try {
            keyStore = KeyStore.getInstance("AndroidKeyStore");
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
// Path: app/src/main/java/rehanced/com/simpleetherwallet/interfaces/FingerprintListener.java
// public interface FingerprintListener {
//     public void authenticationFailed(String error);
// 
//     public void authenticationSucceeded(FingerprintManager.AuthenticationResult result);
// }
// 
// Path: app/src/main/java/rehanced/com/simpleetherwallet/utils/AppLockUtils.java
// public class AppLockUtils {
// 
//     public static boolean hasDeviceFingerprintSupport(Context context) {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//             FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
//             if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
//                 return false;
//             }
//             return fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints();
//         } else {
//             return false;
//         }
//     }
// 
// }
// 
// Path: app/src/main/java/rehanced/com/simpleetherwallet/utils/FingerprintHelper.java
// @RequiresApi(api = Build.VERSION_CODES.M)
// public class FingerprintHelper extends FingerprintManager.AuthenticationCallback {
// 
//     private FingerprintListener listener;
// 
//     public FingerprintHelper(FingerprintListener listener) {
//         this.listener = listener;
//     }
// 
//     private CancellationSignal cancellationSignal;
// 
//     public void startAuth(FingerprintManager manager, FingerprintManager.CryptoObject cryptoObject) {
//         cancellationSignal = new CancellationSignal();
// 
//         try {
//             manager.authenticate(cryptoObject, cancellationSignal, 0, this, null);
//         } catch (SecurityException ex) {
//             listener.authenticationFailed("An error occurred:\n" + ex.getMessage());
//         } catch (Exception ex) {
//             listener.authenticationFailed("An error occurred\n" + ex.getMessage());
//         }
//     }
// 
//     public void cancel() {
//         if (cancellationSignal != null)
//             cancellationSignal.cancel();
//     }
// 
//     @Override
//     public void onAuthenticationError(int errMsgId, CharSequence errString) {
//         listener.authenticationFailed(errString.toString());
//     }
// 
//     @Override
//     public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
//         listener.authenticationFailed(helpString.toString());
//     }
// 
//     @Override
//     public void onAuthenticationFailed() {
//         listener.authenticationFailed("Authentication failed");
//     }
// 
//     @Override
//     public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
//         listener.authenticationSucceeded(result);
//     }
// 
// }


// Path: app/src/main/java/rehanced/com/simpleetherwallet/activities/AppLockActivity.java
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import androidx.annotation.RequiresApi;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
import java.security.KeyStore;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import me.zhanghai.android.patternlock.PatternUtils;
import me.zhanghai.android.patternlock.PatternView;
import rehanced.com.simpleetherwallet.R;
import rehanced.com.simpleetherwallet.interfaces.FingerprintListener;
import rehanced.com.simpleetherwallet.utils.AppLockUtils;
import rehanced.com.simpleetherwallet.utils.FingerprintHelper;

    @RequiresApi(api = Build.VERSION_CODES.M)
    public boolean cipherInit() {
        try {
            cipher = Cipher.getInstance(
                    KeyProperties.KEY_ALGORITHM_AES + "/"
                            + KeyProperties.BLOCK_MODE_CBC + "/"
                            + KeyProperties.ENCRYPTION_PADDING_PKCS7);
        } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
            e.printStackTrace();
        }

        try {
            keyStore.load(null);
            SecretKey key = (SecretKey) keyStore.getKey("Lunary", null);
            cipher.init(Cipher.ENCRYPT_MODE, key);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    protected void generateKey() {
        try {
            keyStore = KeyStore.getInstance("AndroidKeyStore");
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
        try {