当前位置: 首页>>代码示例>>Java>>正文


Java KeyPermanentlyInvalidatedException类代码示例

本文整理汇总了Java中android.security.keystore.KeyPermanentlyInvalidatedException的典型用法代码示例。如果您正苦于以下问题:Java KeyPermanentlyInvalidatedException类的具体用法?Java KeyPermanentlyInvalidatedException怎么用?Java KeyPermanentlyInvalidatedException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KeyPermanentlyInvalidatedException类属于android.security.keystore包,在下文中一共展示了KeyPermanentlyInvalidatedException类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCipher

import android.security.keystore.KeyPermanentlyInvalidatedException; //导入依赖的package包/类
Cipher createCipher(boolean retry) throws Exception
{
    Key key = GetKey();
    Cipher cipher = Cipher.getInstance(TRANSFORMATION);
    try
    {
        cipher.init(Cipher.ENCRYPT_MODE | Cipher.DECRYPT_MODE, key);
    } catch(KeyPermanentlyInvalidatedException e)
    {
        _keystore.deleteEntry(KEY_NAME);
        if(retry)
        {
            createCipher(false);
        } else
        {
            throw new Exception("Could not create the cipher for fingerprint authentication.", e);
        }
    }
    return cipher;
}
 
开发者ID:CreateChance,项目名称:AndroidFingerPrintDemo,代码行数:21,代码来源:CryptoObjectHelper.java

示例2: createCipher

import android.security.keystore.KeyPermanentlyInvalidatedException; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.M)
public Cipher createCipher(boolean retry) throws Exception
{
    Key key = GetKey();
    Cipher cipher = Cipher.getInstance(TRANSFORMATION);
    try
    {
        cipher.init(Cipher.ENCRYPT_MODE | Cipher.DECRYPT_MODE, key);
    } catch(KeyPermanentlyInvalidatedException e)
    {
        _keystore.deleteEntry(KEY_NAME);
        if(retry)
        {
            createCipher(false);
        } else
        {
            throw new Exception("Could not create the cipher for fingerprint authentication.", e);
        }
    }
    return cipher;
}
 
开发者ID:Alex-Jerry,项目名称:LLApp,代码行数:22,代码来源:CryptoObjectHelper.java

示例3: createCipher

import android.security.keystore.KeyPermanentlyInvalidatedException; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.M)
Cipher createCipher(boolean retry) throws Exception {
    Key key = GetKey();
    Cipher cipher = Cipher.getInstance(TRANSFORMATION);
    try {
        cipher.init(Cipher.ENCRYPT_MODE | Cipher.DECRYPT_MODE, key);
    } catch (KeyPermanentlyInvalidatedException e) {
        _keystore.deleteEntry(KEY_NAME);
        if (retry) {
            createCipher(false);
        } else {
            throw new Exception("Could not create the cipher for fingerprint authentication.", e);
        }
    }
    return cipher;
}
 
开发者ID:RinCode,项目名称:PasswordRecorder,代码行数:17,代码来源:FingerCrypto.java

示例4: signWithAttestationKey

import android.security.keystore.KeyPermanentlyInvalidatedException; //导入依赖的package包/类
@Override
    @TargetApi(Build.VERSION_CODES.M)
    public byte[] signWithAttestationKey(byte[] signedDataValue) throws Exception {
        KeyFactory kf = KeyFactory.getInstance("EC");
        byte[] signature = null;
        try {
            KeyStore ks = KeyStore.getInstance("AndroidKeyStore");
            ks.load(null);
            PrivateKey privateKey = (PrivateKey) ks.getKey(ApplicationContextProvider.ATTEST_KEY, null);
//            PrivateKey privateKey =
//                    kf.generatePrivate(new PKCS8EncodedKeySpec(attestPrivKey));
            java.security.Signature s = java.security.Signature.getInstance("SHA256withECDSA");
            s.initSign(privateKey);
            s.update(SHA.sha(signedDataValue, "SHA-256"));
            signature = s.sign();
        } catch (KeyPermanentlyInvalidatedException invalidatedKeyException) {
            logger.info("invalidatedKeyException=" + invalidatedKeyException);
            //Can happen when user removes the screen lock
            throw new Exception("KeyInvalidatedByAndroidKeyStore");
        } catch (Exception e) {
            logger.info("e=" + e);
            throw new Exception("SystemError");
        }
        return signature;
    }
 
开发者ID:emersonmello,项目名称:dummyuafclient,代码行数:26,代码来源:OperationalParams.java

示例5: isFingerprintKeyValid

import android.security.keystore.KeyPermanentlyInvalidatedException; //导入依赖的package包/类
@TargetApi(23)
public static boolean isFingerprintKeyValid()
{
  try
  {
    KeyStore localKeyStore = KeyStore.getInstance("AndroidKeyStore");
    Cipher localCipher = Cipher.getInstance(TextUtils.join("/", new String[] { "AES", "CBC", "PKCS7Padding" }));
    localKeyStore.load(null);
    SecretKey localSecretKey = (SecretKey)localKeyStore.getKey("FingerprintKey", null);
    if (localSecretKey == null) {
      return true;
    }
    localCipher.init(1, localSecretKey);
    return true;
  }
  catch (Exception localException)
  {
    if ((Build.VERSION.SDK_INT >= 23) && ((localException instanceof KeyPermanentlyInvalidatedException))) {
      return false;
    }
    throw new RuntimeException(localException);
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:24,代码来源:AuthApi.java

示例6: mapCipherFinalOperationException

import android.security.keystore.KeyPermanentlyInvalidatedException; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
Exception mapCipherFinalOperationException(Exception e) {
	boolean shouldThrowKeyPermanentlyInvalidatedException = invalidatedByBiometricEnrollment &&
			Build.VERSION.SDK_INT == 26 /*Build.VERSION_CODES.O*/ &&
			e instanceof IllegalBlockSizeException;
	if (shouldThrowKeyPermanentlyInvalidatedException) {
		Logger.warn("Removing invalidated key.");
		try {
			removeKey(keyName);
		} catch (Exception exception) {
			Logger.error("Removing invalidated key failed.", exception);
		}
		return new KeyPermanentlyInvalidatedException();

	}
	return e;
}
 
开发者ID:Mauin,项目名称:RxFingerprint,代码行数:18,代码来源:CipherProvider.java

示例7: handleRuntimeException

import android.security.keystore.KeyPermanentlyInvalidatedException; //导入依赖的package包/类
@Override
protected boolean handleRuntimeException(SharedPreferenceVault sharedPreferenceVault, int requestCode, Throwable throwable) {
    boolean handled = false;
    if (throwable instanceof UserNotAuthenticatedException) {
        Log.w(TAG, "User authentication expired");
        showAuthenticationScreen(requestCode);
        handled = true;
    } else if (throwable instanceof KeyPermanentlyInvalidatedException) {
        Log.w(TAG, "User changed unlock code and permanently invalidated the key");
        sharedPreferenceVault.rekeyStorage(null);
        completeOperationForRequestCode(requestCode);
        handled = true;
    }
    return handled;
}
 
开发者ID:BottleRocketStudios,项目名称:Android-Vault,代码行数:16,代码来源:KeychainAuthenticatedActivity.java

示例8: initCipher

import android.security.keystore.KeyPermanentlyInvalidatedException; //导入依赖的package包/类
@Nullable private Cipher initCipher(int opmode, @Nullable IvParameterSpec ivParameterSpec) {
    final Cipher cipher = createCipher();
    if (cipher == null) {
        return null;
    }

    final SecretKey secretKey = getOrCreateKey();
    if (secretKey == null) {
        return null;
    }

    try {
        if (ivParameterSpec != null) {
            cipher.init(opmode, secretKey, ivParameterSpec);
        } else {
            cipher.init(opmode, secretKey);
        }
    } catch (KeyPermanentlyInvalidatedException exc) {
        if (Constants.DEBUG) {
            Log.e(TAG, "Could not init cipher, because key is permanently invalidated", exc);
        }
        return null;
    } catch (InvalidAlgorithmParameterException | InvalidKeyException ike) {
        if (Constants.DEBUG) {
            Log.e(TAG, "Could not init cipher", ike);
        }
        return null;
    }

    return cipher;
}
 
开发者ID:amartinz,项目名称:HardwareLibrary,代码行数:32,代码来源:CryptoHelper.java

示例9: getCipherForEncryption

import android.security.keystore.KeyPermanentlyInvalidatedException; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
Cipher getCipherForEncryption() throws IOException, GeneralSecurityException {
	try {
		return cipherForEncryption();
	} catch (KeyPermanentlyInvalidatedException e) {
		Logger.warn("Renewing invalidated key.");
		removeKey(keyName);
		return cipherForEncryption();
	}
}
 
开发者ID:Mauin,项目名称:RxFingerprint,代码行数:11,代码来源:CipherProvider.java

示例10: getSignature

import android.security.keystore.KeyPermanentlyInvalidatedException; //导入依赖的package包/类
@Override
    @TargetApi(Build.VERSION_CODES.M)
    public byte[] getSignature(byte[] signedDataValue, String keyId) throws Exception {
        KeyStore ks = KeyStore.getInstance("AndroidKeyStore");
        ks.load(null);
        PrivateKey privateKey = (PrivateKey) ks.getKey(keyId, null);
        byte[] signature = null;
        try {
            java.security.Signature s = java.security.Signature.getInstance("SHA256withECDSA");
            s.initSign(privateKey);
            s.update(SHA.sha(signedDataValue, "SHA-256"));
            signature = s.sign();

            /********* Test **************/
//            Log.i("TEST","Auth signature obtained...");
//            java.security.Signature ss = java.security.Signature.getInstance("SHA256withECDSA");
//            KeyFactory kf = KeyFactory.getInstance("EC");
//
//            KeyFactory factory = KeyFactory.getInstance(privateKey.getAlgorithm(), "AndroidKeyStore");
//            KeyInfo keyInfo = (KeyInfo) factory.getKeySpec(privateKey, KeyInfo.class);
//            Certificate certificate = ks.getCertificate(keyId);
//            PublicKey publicKey = certificate.getPublicKey();
//            String pkString = android.util.Base64.encodeToString(publicKey.getEncoded(), android.util.Base64.DEFAULT);
//
//            Log.i("TEST", "PublicKey: " + pkString);
//            ss.initVerify(kf.generatePublic(new X509EncodedKeySpec(publicKey.getEncoded())));
//            ss.update(SHA.sha(signedDataValue, "SHA-256"));
//            if(!ss.verify(signature)){
//                Log.i("TEST","verify failed.");
//            }
//            Log.i("TEST","Auth signature verified...");
            /********* Test **************/

        } catch (KeyPermanentlyInvalidatedException invalidatedKeyException) {
            //Can happen when user removes the screen lock
            throw new Exception("KeyInvalidatedByAndroidKeyStore");
        } catch (Exception e) {
            throw new Exception("SystemError: " + e.toString());
        }
        return signature;
    }
 
开发者ID:emersonmello,项目名称:dummyuafclient,代码行数:42,代码来源:OperationalParams.java

示例11: testKeyInvalidatedException

import android.security.keystore.KeyPermanentlyInvalidatedException; //导入依赖的package包/类
@Test
public void testKeyInvalidatedException() throws Exception {
    Throwable throwable = new KeyPermanentlyInvalidatedException();
    assertTrue("Should result to true", RxFingerprint.keyInvalidated(throwable));
}
 
开发者ID:Mauin,项目名称:RxFingerprint,代码行数:6,代码来源:RxFingerprintTest.java

示例12: keyInvalidated

import android.security.keystore.KeyPermanentlyInvalidatedException; //导入依赖的package包/类
/**
 * Checks if the provided {@link Throwable} is of type {@link KeyPermanentlyInvalidatedException}
 * <p/>
 * This would mean that the user has disabled the lock screen on his device or changed the
 * fingerprints stored on the device for authentication.
 * <p/>
 * If the user does this all keys encrypted by {@link RxFingerprint} become permanently
 * invalidated by the Android system. To continue using encryption you have to ask the user to
 * encrypt the original data again. The old data is not accessible anymore.
 *
 * @param throwable Throwable received in {@link org.reactivestreams.Subscriber#onError(Throwable)} from
 *                  an {@link RxFingerprint} encryption method
 * @return {@code true} if the requested key was permanently invalidated and cannot be used
 * anymore
 */
public static boolean keyInvalidated(Throwable throwable) {
    return throwable instanceof KeyPermanentlyInvalidatedException;
}
 
开发者ID:Mauin,项目名称:RxFingerprint,代码行数:19,代码来源:RxFingerprint.java


注:本文中的android.security.keystore.KeyPermanentlyInvalidatedException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。