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