當前位置: 首頁>>代碼示例>>Java>>正文


Java KeyStoreTestSupport類代碼示例

本文整理匯總了Java中org.apache.harmony.security.tests.support.KeyStoreTestSupport的典型用法代碼示例。如果您正苦於以下問題:Java KeyStoreTestSupport類的具體用法?Java KeyStoreTestSupport怎麽用?Java KeyStoreTestSupport使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


KeyStoreTestSupport類屬於org.apache.harmony.security.tests.support包,在下文中一共展示了KeyStoreTestSupport類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setUp

import org.apache.harmony.security.tests.support.KeyStoreTestSupport; //導入依賴的package包/類
protected void setUp() throws Exception {
    super.setUp();
    mProv = (new SpiEngUtils()).new MyProvider("MyKSProvider",
            "Testing provider", KeyStoreTestSupport.srvKeyStore.concat(".")
                    .concat(defaultType), KeyStoreProviderClass);
    Security.insertProviderAt(mProv, 2);
    defaultProvider = SpiEngUtils.isSupport(defaultType,
            KeyStoreTestSupport.srvKeyStore);
    KSSupported = (defaultProvider != null);
    defaultProviderName = (KSSupported ? defaultProvider.getName() : null);
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:12,代碼來源:KeyStoreTest.java

示例2: testSetKeyEntry

import org.apache.harmony.security.tests.support.KeyStoreTestSupport; //導入依賴的package包/類
/**
 * Test for <code>setKeyEntry(String alias, byte[] key, Certificate[] chain)</code> 
 * method 
 * Assertion: stores KeyEntry.
 */
public void testSetKeyEntry() throws Exception {
    assertTrue(NotSupportMsg, KSSupported);
    
    KeyStore[] kss = createKS();
    assertNotNull("KeyStore objects were not created", kss);
    byte[] kk = { (byte) 1, (byte) 2, (byte) 127, (byte) 77 };
    String alias = "keyEntry";
    char[] pwd = new char[0];
    byte[] res;
    Certificate certs[] = {
            new KeyStoreTestSupport.MCertificate(alias, kk),
            new KeyStoreTestSupport.MCertificate(alias, kk) };
    for (int i = 0; i < kss.length; i++) {
        kss[i].load(null, null);
        try {
            kss[i].setKeyEntry("proba", null, null);
            fail("KeyStoreException must be thrown");
        } catch (KeyStoreException e) {
        }
        kss[i].setKeyEntry(alias, kk, certs);
        res = kss[i].getKey(alias, pwd).getEncoded();
        assertEquals(kk.length, res.length);
        for (int j = 0; j < res.length; j++) {
            assertEquals(res[j], kk[j]);
        }
        assertEquals(kss[i].getCertificateChain(alias).length, certs.length);
        kss[i].setKeyEntry(alias, kk, null);
        res = kss[i].getKey(alias, pwd).getEncoded();
        assertEquals(kk.length, res.length);
        for (int j = 0; j < res.length; j++) {
            assertEquals(res[j], kk[j]);
        }
        assertNull(kss[i].getCertificateChain(alias));
    }
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:41,代碼來源:KeyStoreTest.java

示例3: setUp

import org.apache.harmony.security.tests.support.KeyStoreTestSupport; //導入依賴的package包/類
protected void setUp() throws Exception {
    super.setUp();
    mProv = (new SpiEngUtils()).new MyProvider("MyKSProvider",
            "Testing provider", KeyStoreTestSupport.srvKeyStore.concat(".").concat(
                    defaultAlg), KeyStoreProviderClass);
    Security.insertProviderAt(mProv, 2);
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:8,代碼來源:KeyStore_Impl2Test.java

示例4: testSetKeyEntry

import org.apache.harmony.security.tests.support.KeyStoreTestSupport; //導入依賴的package包/類
/**
 * Test for <code>setKeyEntry(String alias, byte[] key, Certificate[] chain)</code>
 * method
 * Assertion: stores KeyEntry.
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "setKeyEntry",
    args = {java.lang.String.class, byte[].class, java.security.cert.Certificate[].class}
)
public void testSetKeyEntry() throws Exception {
    assertTrue(NotSupportMsg, KSSupported);

    KeyStore[] kss = createKS();
    assertNotNull("KeyStore objects were not created", kss);
    byte[] kk = { (byte) 1, (byte) 2, (byte) 127, (byte) 77 };
    String alias = "keyEntry";
    char[] pwd = new char[0];
    byte[] res;
    Certificate certs[] = {
            new KeyStoreTestSupport.MCertificate(alias, kk),
            new KeyStoreTestSupport.MCertificate(alias, kk) };
    for (int i = 0; i < kss.length; i++) {
        kss[i].load(null, null);
        try {
            kss[i].setKeyEntry("proba", null, null);
            fail("KeyStoreException must be thrown");
        } catch (KeyStoreException e) {
        }
        kss[i].setKeyEntry(alias, kk, certs);
        res = kss[i].getKey(alias, pwd).getEncoded();
        assertEquals(kk.length, res.length);
        for (int j = 0; j < res.length; j++) {
            assertEquals(res[j], kk[j]);
        }
        assertEquals(kss[i].getCertificateChain(alias).length, certs.length);
        kss[i].setKeyEntry(alias, kk, null);
        res = kss[i].getKey(alias, pwd).getEncoded();
        assertEquals(kk.length, res.length);
        for (int j = 0; j < res.length; j++) {
            assertEquals(res[j], kk[j]);
        }
        assertNull(kss[i].getCertificateChain(alias));
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:47,代碼來源:KeyStoreTest.java

示例5: testEntry06

import org.apache.harmony.security.tests.support.KeyStoreTestSupport; //導入依賴的package包/類
/**
 * Test for 
 * <code>deleteEntry(String alias)</code>
 * <code>size()</code> 
 * methods
 * Assertions: 
 * throws NullPointerException when alias is null;
 * 
 * deletes entry from KeyStore.
 * 
 */    
public void testEntry06() throws Exception {
    assertTrue(NotSupportMsg, JKSSupported);
    KeyStore.TrustedCertificateEntry tCert = new KeyStore.TrustedCertificateEntry(
            new KeyStoreTestSupport.MCertificate("type", new byte[0]));

    TestKeyPair tkp = new TestKeyPair("DSA");
    KeyStoreTestSupport.MCertificate certs[] = {
            new KeyStoreTestSupport.MCertificate("DSA", tkp.getPrivate()
                    .getEncoded()),
            new KeyStoreTestSupport.MCertificate("DSA", tkp.getPrivate()
                    .getEncoded()) };
    KeyStore.PrivateKeyEntry pKey = new KeyStore.PrivateKeyEntry(tkp
            .getPrivate(), certs);
    char[] pwd = { 'p', 'a', 's', 's', 'w', 'd' };
    KeyStore.PasswordProtection pp = new KeyStore.PasswordProtection(pwd);

    String[] aliases = { "Alias1", "Alias2", "Alias3", "Alias4", "Alias5" };

    KeyStore[] kss = createKS();
    assertNotNull("KeyStore objects were not created", kss);

    for (int i = 0; i < kss.length; i++) {
        kss[i].load(null, null);
        kss[i].setEntry(aliases[0], tCert, null);
        kss[i].setEntry(aliases[1], pKey, pp);
        kss[i].setEntry(aliases[2], pKey, pp);

        kss[i].setKeyEntry(aliases[3], tkp.getPrivate(), pwd, certs);

        kss[i].setCertificateEntry(aliases[4], certs[0]);

        assertEquals("Incorrect size", kss[i].size(), 5);
        try {
            kss[i].deleteEntry(null);
            fail("NullPointerException should be thrown when alias is null");
        } catch (NullPointerException e) {
        }
        kss[i].deleteEntry(aliases[0]);
        kss[i].deleteEntry(aliases[3]);
        assertEquals("Incorrect size", kss[i].size(), 3);
        for (int j = 1; j < 5; j++) {
            if ((j == 0) || (j == 3)) {
                assertFalse("Incorrect deleted alias", kss[i]
                        .containsAlias(aliases[j]));
            } else {
                assertTrue("Incorrect alias", kss[i]
                        .containsAlias(aliases[j]));
            }
        }
    }
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:63,代碼來源:KeyStore_Impl1Test.java


注:本文中的org.apache.harmony.security.tests.support.KeyStoreTestSupport類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。