当前位置: 首页>>代码示例>>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;未经允许,请勿转载。