android/src/main/java/dev/mcodex/RNSensitiveInfo/RNSensitiveInfoModule.java
/**
     * Generates a new RSA key and stores it under the { @code KEY_ALIAS } in the
     * Android Keystore.
     */
Generates a new RSA key and stores it under the { @code KEY_ALIAS } in the
Android Keystore.
Generates a new RSA key and stores it under the { @code KEY_ALIAS } in the Android Keystore .
private void initKeyStore() {
        try {
            if (!mKeyStore.containsAlias(KEY_ALIAS)) {
                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, ANDROID_KEYSTORE_PROVIDER);
                    keyGenerator.init(
                            new KeyGenParameterSpec.Builder(KEY_ALIAS,
                                KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
                                .setBlockModes(KeyProperties.BLOCK_MODE_GCM)
                                .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
                                .setRandomizedEncryptionRequired(false)
                                .build());
                    keyGenerator.generateKey();
                } else {
                    Calendar notBefore = Calendar.getInstance();
                    Calendar notAfter = Calendar.getInstance();
                    notAfter.add(Calendar.YEAR, 10);
                    KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(getReactApplicationContext())
                        .setAlias(KEY_ALIAS)
                        .setSubject(new X500Principal("CN=" + KEY_ALIAS))
                        .setSerialNumber(BigInteger.valueOf(1337))
                        .setStartDate(notBefore.getTime())
                        .setEndDate(notAfter.getTime())
                        .build();
                    KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("RSA", ANDROID_KEYSTORE_PROVIDER);
                    kpGenerator.initialize(spec);
                    kpGenerator.generateKeyPair();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
private void initKeyStore ( ) { try { if ( ! mKeyStore . containsAlias ( KEY_ALIAS ) ) { if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . M ) { KeyGenerator keyGenerator = KeyGenerator . getInstance ( KeyProperties . KEY_ALGORITHM_AES , ANDROID_KEYSTORE_PROVIDER ) ; keyGenerator . init ( new KeyGenParameterSpec . Builder ( KEY_ALIAS , KeyProperties . PURPOSE_ENCRYPT | KeyProperties . PURPOSE_DECRYPT ) . setBlockModes ( KeyProperties . BLOCK_MODE_GCM ) . setEncryptionPaddings ( KeyProperties . ENCRYPTION_PADDING_NONE ) . setRandomizedEncryptionRequired ( false ) . build ( ) ) ; keyGenerator . generateKey ( ) ; } else { Calendar notBefore = Calendar . getInstance ( ) ; Calendar notAfter = Calendar . getInstance ( ) ; notAfter . add ( Calendar . YEAR , 10 ) ; KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec . Builder ( getReactApplicationContext ( ) ) . setAlias ( KEY_ALIAS ) . setSubject ( new X500Principal ( "CN=" + KEY_ALIAS ) ) . setSerialNumber ( BigInteger . valueOf ( 1337 ) ) . setStartDate ( notBefore . getTime ( ) ) . setEndDate ( notAfter . getTime ( ) ) . build ( ) ; KeyPairGenerator kpGenerator = KeyPairGenerator . getInstance ( "RSA" , ANDROID_KEYSTORE_PROVIDER ) ; kpGenerator . initialize ( spec ) ; kpGenerator . generateKeyPair ( ) ; } } } catch ( Exception e ) { e . printStackTrace ( ) ; } }
Generates a new RSA key and stores it under the { @code KEY_ALIAS } in the
 Android Keystore.
Generates a new RSA key and stores it under the { @code KEY_ALIAS } in the Android Keystore .