use of java.security.spec.KeySpec in project robovm by robovm.
the class DSAPublicKeySpecTest method testDSAPublicKeySpec.
/**
* Test for <code>DSAPublicKeySpec</code> ctor
*/
public final void testDSAPublicKeySpec() {
KeySpec ks = new DSAPublicKeySpec(// y
new BigInteger("1"), // p
new BigInteger("2"), // q
new BigInteger("3"), // g
new BigInteger("4"));
assertTrue(ks instanceof DSAPublicKeySpec);
}
use of java.security.spec.KeySpec in project robovm by robovm.
the class SecretKeyFactorySpiTest method testSecretKeyFactorySpi01.
/**
* Test for <code>SecretKeyFactorySpi</code> constructor Assertion:
* constructs SecretKeyFactorySpi
*/
public void testSecretKeyFactorySpi01() throws InvalidKeyException, InvalidKeySpecException {
Mock_SecretKeyFactorySpi skfSpi = new Mock_SecretKeyFactorySpi();
SecretKey sk = null;
assertNull("Not null result", skfSpi.engineTranslateKey(sk));
KeySpec kspec = null;
assertNull("Not null result", skfSpi.engineGenerateSecret(kspec));
assertNull("Not null result", skfSpi.engineGetKeySpec(sk, null));
}
use of java.security.spec.KeySpec in project robovm by robovm.
the class mySecretKeyFactory method testSecretKeyFactory10.
/**
* Test for <code>generateSecret(KeySpec keySpec)</code> and
* <code>getKeySpec(SecretKey key, Class keySpec)
* methods
* Assertion:
* throw InvalidKeySpecException if parameter is inappropriate
*/
public void testSecretKeyFactory10() throws InvalidKeyException, InvalidKeySpecException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
byte[] bb = new byte[24];
KeySpec ks = (defaultAlgorithm.equals(defaultAlgorithm2) ? (KeySpec) new DESKeySpec(bb) : (KeySpec) new DESedeKeySpec(bb));
KeySpec rks = null;
SecretKeySpec secKeySpec = new SecretKeySpec(bb, defaultAlgorithm);
SecretKey secKey = null;
SecretKeyFactory[] skF = createSKFac();
assertNotNull("SecretKeyFactory object were not created", skF);
for (int i = 0; i < skF.length; i++) {
try {
skF[i].generateSecret(null);
fail("generateSecret(null): InvalidKeySpecException must be thrown");
} catch (InvalidKeySpecException e) {
}
secKey = skF[i].generateSecret(ks);
try {
skF[i].getKeySpec(null, null);
fail("getKeySpec(null,null): InvalidKeySpecException must be thrown");
} catch (InvalidKeySpecException e) {
}
try {
skF[i].getKeySpec(null, ks.getClass());
fail("getKeySpec(null, Class): InvalidKeySpecException must be thrown");
} catch (InvalidKeySpecException e) {
}
try {
skF[i].getKeySpec(secKey, null);
fail("getKeySpec(secKey, null): NullPointerException or InvalidKeySpecException must be thrown");
} catch (InvalidKeySpecException e) {
// Expected
} catch (NullPointerException e) {
// Expected
}
try {
Class c;
if (defaultAlgorithm.equals(defaultAlgorithm2)) {
c = DESedeKeySpec.class;
} else {
c = DESKeySpec.class;
}
skF[i].getKeySpec(secKeySpec, c);
fail("getKeySpec(secKey, Class): InvalidKeySpecException must be thrown");
} catch (InvalidKeySpecException e) {
}
rks = skF[i].getKeySpec(secKeySpec, ks.getClass());
if (defaultAlgorithm.equals(defaultAlgorithm1)) {
assertTrue("Incorrect getKeySpec() result 1", rks instanceof DESedeKeySpec);
} else {
assertTrue("Incorrect getKeySpec() result 1", rks instanceof DESKeySpec);
}
rks = skF[i].getKeySpec(secKey, ks.getClass());
if (defaultAlgorithm.equals(defaultAlgorithm1)) {
assertTrue("Incorrect getKeySpec() result 2", rks instanceof DESedeKeySpec);
} else {
assertTrue("Incorrect getKeySpec() result 2", rks instanceof DESKeySpec);
}
}
}
use of java.security.spec.KeySpec in project robovm by robovm.
the class SecretKeyFactoryThread method test.
@Override
public void test() throws Exception {
SecretKeyFactory skf = SecretKeyFactory.getInstance(algName);
byte[] b = new byte[24];
KeySpec ks = (KeySpec) ((algName == "DES") ? new DESKeySpec(b) : (algName == "DESede") ? new DESedeKeySpec(b) : new PBEKeySpec("passw".toCharArray()));
skf.generateSecret(ks);
}
use of java.security.spec.KeySpec in project syncany by syncany.
the class CipherUtil method createMasterKey.
public static SaltedSecretKey createMasterKey(String password, byte[] salt) throws CipherException {
try {
logger.log(Level.FINE, "- Creating secret key using {0} with {1} rounds, key size {2} bit ...", new Object[] { MASTER_KEY_DERIVATION_FUNCTION, MASTER_KEY_DERIVATION_ROUNDS, MASTER_KEY_SIZE });
SecretKeyFactory factory = SecretKeyFactory.getInstance(MASTER_KEY_DERIVATION_FUNCTION);
KeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray(), salt, MASTER_KEY_DERIVATION_ROUNDS, MASTER_KEY_SIZE);
SecretKey masterKey = factory.generateSecret(pbeKeySpec);
return new SaltedSecretKey(masterKey, salt);
} catch (Exception e) {
throw new CipherException(e);
}
}
Aggregations