use of java.security.AlgorithmParameters in project robovm by robovm.
the class AlgorithmParameterGeneratorTest method testAlgorithmParameterGenerator.
public void testAlgorithmParameterGenerator() {
AlgorithmParameterGenerator generator = null;
try {
generator = AlgorithmParameterGenerator.getInstance(algorithmName);
} catch (NoSuchAlgorithmException e) {
fail(e.getMessage());
}
generator.init(1024);
AlgorithmParameters parameters = generator.generateParameters();
assertNotNull("generated parameters are null", parameters);
helper.test(parameters);
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class AlgorithmParametersTest method testAlgorithmParameters.
public void testAlgorithmParameters() {
AlgorithmParameters algorithmParameters = null;
try {
algorithmParameters = AlgorithmParameters.getInstance(algorithmName);
} catch (NoSuchAlgorithmException e) {
fail(e.getMessage());
}
try {
algorithmParameters.init(parameterData);
} catch (InvalidParameterSpecException e) {
fail(e.getMessage());
}
helper.test(algorithmParameters);
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class OpenSSLCipher method engineGetParameters.
@Override
protected AlgorithmParameters engineGetParameters() {
if (iv != null && iv.length > 0) {
try {
AlgorithmParameters params = AlgorithmParameters.getInstance(getBaseCipherName());
params.init(iv);
return params;
} catch (NoSuchAlgorithmException e) {
return null;
} catch (IOException e) {
return null;
}
}
return null;
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class ExemptionMechanismSpiTest method testExemptionMechanismSpi01.
/**
* Test for <code>ExemptionMechanismSpi</code> constructor Assertion:
* constructs ExemptionMechanismSpi
* @throws Exception
*/
public void testExemptionMechanismSpi01() throws Exception {
Mock_ExemptionMechanismSpi emSpi = new Mock_ExemptionMechanismSpi() {
};
int len = MyExemptionMechanismSpi.getLength();
byte[] bbRes = emSpi.engineGenExemptionBlob();
assertEquals("Incorrect length", bbRes.length, len);
assertEquals("Incorrect result", emSpi.engineGenExemptionBlob(new byte[1], len), len);
assertEquals("Incorrect output size", 10, emSpi.engineGetOutputSize(100));
Key key = null;
AlgorithmParameters params = null;
AlgorithmParameterSpec parSpec = null;
try {
emSpi.engineInit(key);
fail("InvalidKeyException must be thrown");
} catch (InvalidKeyException e) {
}
try {
emSpi.engineInit(key, params);
fail("InvalidKeyException must be thrown");
} catch (InvalidKeyException e) {
}
try {
emSpi.engineInit(key, parSpec);
fail("InvalidKeyException must be thrown");
} catch (InvalidKeyException e) {
}
key = ((MyExemptionMechanismSpi) emSpi).new tmp1Key("Proba", new byte[0]);
try {
emSpi.engineInit(key);
fail("ExemptionMechanismException must be thrown");
} catch (ExemptionMechanismException e) {
}
try {
emSpi.engineInit(key, params);
fail("ExemptionMechanismException must be thrown");
} catch (ExemptionMechanismException e) {
}
try {
emSpi.engineInit(key, parSpec);
fail("ExemptionMechanismException must be thrown");
} catch (ExemptionMechanismException e) {
}
key = ((MyExemptionMechanismSpi) emSpi).new tmpKey("Proba", new byte[0]);
emSpi.engineInit(key);
emSpi.engineInit(key, AlgorithmParameters.getInstance("DH"));
emSpi.engineInit(key, new RSAKeyGenParameterSpec(10, new BigInteger("10")));
assertEquals("Incorrect result", 10, emSpi.engineGetOutputSize(100));
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray2.
/**
* Test #2 for
* <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[])
* </code>
* constructor <br>
* Assertion: <code>NullPointerException</code>- if the specified
* algorithm parameters or encrypted data is <code>null</code><br>
* Test preconditions: pass <code>null</code> as algorithm parameters then
* as encrypted data <br>
* Expected: <code>NullPointerException</code> in both cases
*
* @throws NoSuchAlgorithmException
* @throws IOException
*/
public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray2() throws NoSuchAlgorithmException, IOException {
// 1: pass null as AlgorithmParameters
try {
new EncryptedPrivateKeyInfo((AlgorithmParameters) null, EncryptedPrivateKeyInfoData.encryptedData);
fail(getName() + ": NullPointerException has not been thrown");
} catch (NullPointerException ok) {
}
// 2: pass null as encrypted data
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance("DSA");
// use pregenerated AlgorithmParameters encodings
ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding("DSA"));
new EncryptedPrivateKeyInfo(ap, null);
fail(getName() + ": NullPointerException has not been thrown");
} catch (NullPointerException ok) {
}
}
Aggregations