use of javax.crypto.SecretKeyFactory in project robovm by robovm.
the class mySecretKeyFactory method test_getAlgorithm.
public void test_getAlgorithm() throws NoSuchAlgorithmException {
for (int i = 0; i < validValues.length; i++) {
SecretKeyFactory secKF = SecretKeyFactory.getInstance(validValues[i]);
assertEquals("Incorrect algorithm", secKF.getAlgorithm(), validValues[i]);
}
Mock_SecretKeyFactory msf = new Mock_SecretKeyFactory(null, null, null);
assertNull(msf.getAlgorithm());
}
use of javax.crypto.SecretKeyFactory in project robovm by robovm.
the class mySecretKeyFactory method test_getProvider.
public void test_getProvider() throws NoSuchAlgorithmException {
for (int i = 0; i < validValues.length; i++) {
SecretKeyFactory secKF = SecretKeyFactory.getInstance(validValues[i]);
assertNotNull(secKF.getProvider());
}
Mock_SecretKeyFactory msf = new Mock_SecretKeyFactory(null, null, null);
assertNull(msf.getProvider());
}
use of javax.crypto.SecretKeyFactory in project robovm by robovm.
the class mySecretKeyFactory method testSecretKeyFactory06.
/**
* Test for <code>getInstance(String algorithm, String provider)</code>
* method
* Assertion: returns SecretKeyFactory object
*/
public void testSecretKeyFactory06() throws NoSuchProviderException, NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
for (int i = 0; i < validValues.length; i++) {
SecretKeyFactory secKF = SecretKeyFactory.getInstance(validValues[i], defaultProviderName);
assertEquals("Incorrect algorithm", secKF.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider", secKF.getProvider().getName(), defaultProviderName);
}
}
use of javax.crypto.SecretKeyFactory in project robovm by robovm.
the class CipherPBEThread method crypt.
@Override
public void crypt() throws Exception {
byte[] output = new byte[128];
byte[] decrypted = new byte[128];
byte[] input = getData().getBytes();
byte[] salt = new byte[8];
SecureRandom sr = new SecureRandom();
PBEKeySpec keySpec = new PBEKeySpec("top sicret password".toCharArray());
SecretKeyFactory skf = SecretKeyFactory.getInstance(getAlgName());
SecretKey key = skf.generateSecret(keySpec);
Cipher cip = Cipher.getInstance(getAlgName() + "/" + getMode() + "/" + getPadding());
sr.nextBytes(salt);
PBEParameterSpec parSpec = new PBEParameterSpec(salt, getKeyLength());
cip.init(Cipher.ENCRYPT_MODE, key, parSpec);
cip.doFinal(input, 0, input.length, output);
int outputSize = cip.getOutputSize(input.length);
cip.init(Cipher.DECRYPT_MODE, key, parSpec);
cip.doFinal(output, 0, outputSize, decrypted);
checkEncodedData(getData().getBytes(), decrypted);
}
use of javax.crypto.SecretKeyFactory 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);
}
Aggregations