use of java.security.spec.DSAPrivateKeySpec in project robovm by robovm.
the class KeyStore2Test method test_setEntry.
/**
* java.security.KeyStore#setEntry(String, KeyStore.Entry,
* KeyStore.ProtectionParameter)
*/
public void test_setEntry() throws Exception {
String type = "DSA";
KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
keyTest.load(null, pssWord);
Certificate[] chain = { new MyCertificate(type, testEncoding), new MyCertificate(type, testEncoding) };
DSAPrivateKey privateKey1 = (DSAPrivateKey) KeyFactory.getInstance(type).generatePrivate(new DSAPrivateKeySpec(new BigInteger("1"), new BigInteger("2"), new BigInteger("3"), new BigInteger("4")));
KeyStore.PasswordProtection pp = new KeyStore.PasswordProtection(pssWord);
KeyStore.PrivateKeyEntry pke = new KeyStore.PrivateKeyEntry(getPrivateKey(), chain);
KeyStore.PrivateKeyEntry pke1 = new KeyStore.PrivateKeyEntry(privateKey1, chain);
try {
keyTest.setEntry("alias", pke, null);
// BKS KeyStore does not require a password
assertFalse(StandardNames.IS_RI);
} catch (KeyStoreException e) {
// JKS KeyStore requires a password
assertTrue(StandardNames.IS_RI);
}
keyTest.setEntry("alias", pke, pp);
KeyStore.PrivateKeyEntry pkeActual = (KeyStore.PrivateKeyEntry) keyTest.getEntry("alias", pp);
assertTrue(Arrays.equals(chain, pkeActual.getCertificateChain()));
assertEquals(getPrivateKey(), pkeActual.getPrivateKey());
assertEquals(new MyCertificate(type, testEncoding), pkeActual.getCertificate());
assertTrue(keyTest.entryInstanceOf("alias", KeyStore.PrivateKeyEntry.class));
keyTest.setEntry("alias", pke1, pp);
pkeActual = (KeyStore.PrivateKeyEntry) keyTest.getEntry("alias", pp);
assertTrue(Arrays.equals(chain, pkeActual.getCertificateChain()));
DSAPrivateKey actualPrivateKey = (DSAPrivateKey) pkeActual.getPrivateKey();
assertEquals(privateKey1.getX(), actualPrivateKey.getX());
assertEquals(privateKey1.getParams().getG(), actualPrivateKey.getParams().getG());
assertEquals(privateKey1.getParams().getP(), actualPrivateKey.getParams().getP());
assertEquals(privateKey1.getParams().getQ(), actualPrivateKey.getParams().getQ());
assertEquals(new MyCertificate(type, testEncoding), pkeActual.getCertificate());
assertTrue(keyTest.entryInstanceOf("alias", KeyStore.PrivateKeyEntry.class));
keyTest.setEntry("alias2", pke1, pp);
pkeActual = (KeyStore.PrivateKeyEntry) keyTest.getEntry("alias2", pp);
assertTrue(Arrays.equals(chain, pkeActual.getCertificateChain()));
actualPrivateKey = (DSAPrivateKey) pkeActual.getPrivateKey();
assertEquals(privateKey1.getX(), actualPrivateKey.getX());
assertEquals(privateKey1.getParams().getG(), actualPrivateKey.getParams().getG());
assertEquals(privateKey1.getParams().getP(), actualPrivateKey.getParams().getP());
assertEquals(privateKey1.getParams().getQ(), actualPrivateKey.getParams().getQ());
assertEquals(new MyCertificate(type, testEncoding), pkeActual.getCertificate());
assertTrue(keyTest.entryInstanceOf("alias2", KeyStore.PrivateKeyEntry.class));
try {
keyTest.setEntry(null, null, null);
fail();
} catch (NullPointerException expected) {
}
}
use of java.security.spec.DSAPrivateKeySpec in project robovm by robovm.
the class KeyStore2Test method test_getEntry.
/**
* java.security.KeyStore#getEntry(String,
* KeyStore.ProtectionParameter)
*/
public void test_getEntry() throws Exception {
String type = "DSA";
KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
try {
keyTest.getEntry("anAlias", new KeyStore.PasswordProtection(new char[] {}));
fail();
} catch (KeyStoreException expected) {
}
keyTest.load(null, pssWord);
try {
keyTest.getEntry(null, new KeyStore.PasswordProtection(new char[] {}));
fail();
} catch (NullPointerException expected) {
}
keyTest.getEntry("anAlias", null);
try {
keyTest.getEntry(null, null);
fail();
} catch (NullPointerException expected) {
}
assertNull(keyTest.getEntry("alias", null));
Certificate[] chain = { new MyCertificate(type, testEncoding), new MyCertificate(type, testEncoding) };
DSAPrivateKey privateKey1 = (DSAPrivateKey) KeyFactory.getInstance(type).generatePrivate(new DSAPrivateKeySpec(new BigInteger("1"), new BigInteger("2"), new BigInteger("3"), new BigInteger("4")));
KeyStore.PasswordProtection pp = new KeyStore.PasswordProtection(pssWord);
assertNull(keyTest.getEntry("alias", pp));
KeyStore.PrivateKeyEntry pke1 = new KeyStore.PrivateKeyEntry(getPrivateKey(), chain);
KeyStore.PrivateKeyEntry pke2 = new KeyStore.PrivateKeyEntry(privateKey1, chain);
keyTest.setEntry("alias1", pke1, pp);
keyTest.setEntry("alias2", pke2, pp);
assertNull(keyTest.getEntry("alias", pp));
KeyStore.PrivateKeyEntry pkeActual1 = (KeyStore.PrivateKeyEntry) keyTest.getEntry("alias1", pp);
KeyStore.PrivateKeyEntry pkeActual2 = (KeyStore.PrivateKeyEntry) keyTest.getEntry("alias2", pp);
assertTrue(Arrays.equals(chain, pkeActual1.getCertificateChain()));
assertEquals(getPrivateKey(), pkeActual1.getPrivateKey());
assertEquals(new MyCertificate(type, testEncoding), pkeActual1.getCertificate());
assertTrue(keyTest.entryInstanceOf("alias1", KeyStore.PrivateKeyEntry.class));
assertTrue(Arrays.equals(chain, pkeActual2.getCertificateChain()));
DSAPrivateKey entryPrivateKey = (DSAPrivateKey) pkeActual2.getPrivateKey();
assertEquals(privateKey1.getX(), entryPrivateKey.getX());
assertEquals(privateKey1.getParams().getG(), entryPrivateKey.getParams().getG());
assertEquals(privateKey1.getParams().getP(), entryPrivateKey.getParams().getP());
assertEquals(privateKey1.getParams().getQ(), entryPrivateKey.getParams().getQ());
assertEquals(new MyCertificate(type, testEncoding), pkeActual2.getCertificate());
assertTrue(keyTest.entryInstanceOf("alias2", KeyStore.PrivateKeyEntry.class));
}
use of java.security.spec.DSAPrivateKeySpec in project robovm by robovm.
the class DSAPrivateKeySpecTest method testDSAPrivateKeySpec.
/**
* Test for constructor
*/
public final void testDSAPrivateKeySpec() {
KeySpec ks = new DSAPrivateKeySpec(new BigInteger("1"), new BigInteger("2"), new BigInteger("3"), new BigInteger("4"));
assertTrue(ks instanceof DSAPrivateKeySpec);
}
use of java.security.spec.DSAPrivateKeySpec in project robovm by robovm.
the class DSAPrivateKeySpecTest method testGetQ.
/**
* getQ() test
*/
public final void testGetQ() {
DSAPrivateKeySpec dpks = new DSAPrivateKeySpec(new BigInteger("1"), new BigInteger("2"), new BigInteger("3"), new BigInteger("4"));
assertEquals(3, dpks.getQ().intValue());
}
use of java.security.spec.DSAPrivateKeySpec in project robovm by robovm.
the class DSAPrivateKeySpecTest method testGetP.
/**
* getP() test
*/
public final void testGetP() {
DSAPrivateKeySpec dpks = new DSAPrivateKeySpec(new BigInteger("1"), new BigInteger("2"), new BigInteger("3"), new BigInteger("4"));
assertEquals(2, dpks.getP().intValue());
}
Aggregations