FileDocCategorySizeDatePackage
SystemKeyStoreTest.javaAPI DocAndroid 5.1 API2946Thu Mar 12 22:22:30 GMT 2015android.security

SystemKeyStoreTest

public class SystemKeyStoreTest extends android.test.ActivityUnitTestCase
Junit / Instrumentation test case for KeyStore class Running the test suite: runtest keystore-unit Or this individual test case: runtest --path frameworks/base/keystore/tests/src/android/security/SystemKeyStoreTest.java

Fields Summary
private static final String
keyName
private static final String
keyName2
private android.security.SystemKeyStore
mSysKeyStore
Constructors Summary
public SystemKeyStoreTest()


      
        super(Activity.class);
    
Methods Summary
protected voidsetUp()

        mSysKeyStore = SystemKeyStore.getInstance();
        try {
            mSysKeyStore.deleteKey(keyName);
            mSysKeyStore.deleteKey(keyName2);
        } catch (Exception e) { }
        super.setUp();
    
protected voidtearDown()

        try {
            mSysKeyStore.deleteKey(keyName);
            mSysKeyStore.deleteKey(keyName2);
        } catch (Exception e) { }
        super.tearDown();
    
public voidtestBasicAccess()

        try {
            byte[] newKey = mSysKeyStore.generateNewKey(128, "AES", keyName);
            assertNotNull(newKey);
            byte[] recKey = mSysKeyStore.retrieveKey(keyName);
            assertEquals(newKey.length, recKey.length);
            for (int i = 0; i < newKey.length; i++) {
                assertEquals(newKey[i], recKey[i]);
            }
            mSysKeyStore.deleteKey(keyName);
            byte[] nullKey = mSysKeyStore.retrieveKey(keyName);
            assertNull(nullKey);

            String newKeyStr = mSysKeyStore.generateNewKeyHexString(128, "AES", keyName2);
            assertNotNull(newKeyStr);
            String recKeyStr = mSysKeyStore.retrieveKeyHexString(keyName2);
            assertEquals(newKeyStr, recKeyStr);

            mSysKeyStore.deleteKey(keyName2);
            String nullKey2 = mSysKeyStore.retrieveKeyHexString(keyName2);
            assertNull(nullKey2);
        } catch (Exception e) {
            fail();
        }