delete Key from KeyStore - Android java.security

Android examples for java.security:KeyStore

Description

delete Key from KeyStore

Demo Code


//package com.java2s;

import java.io.IOException;

import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;

import java.security.cert.CertificateException;

public class Main {
    public static final String KEY_STORE_TYPE = "AndroidKeyStore";

    public static boolean deleteKey(String alias) {
        try {/*from  w  w w .  jav  a  2 s  .c o m*/
            KeyStore keyStore = KeyStore.getInstance(KEY_STORE_TYPE);
            keyStore.load(null);
            keyStore.deleteEntry(alias);
            return true;
        } catch (KeyStoreException | CertificateException | IOException
                | NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return false;
    }
}

Related Tutorials