本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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));
}
示例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;
}