use of javax.crypto.EncryptedPrivateKeyInfo in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testGetEncryptedData03.
/**
* Test #3 for <code>getEncryptedData()</code> method <br>
* Assertion: returns the encrypted data <br>
* Test preconditions: test object created using ctor which takes algorithm
* parameters and encrypted data as a parameters <br>
* Expected: the equivalent encrypted data must be returned
*
* @throws IOException
*/
public final void testGetEncryptedData03() throws IOException {
boolean performed = false;
for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance(EncryptedPrivateKeyInfoData.algName0[i][0]);
// use pregenerated AlgorithmParameters encodings
ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding(EncryptedPrivateKeyInfoData.algName0[i][0]));
EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(ap, EncryptedPrivateKeyInfoData.encryptedData);
// check that method under test returns
// valid encrypted data
assertTrue(Arrays.equals(EncryptedPrivateKeyInfoData.encryptedData, epki.getEncryptedData()));
performed = true;
} catch (NoSuchAlgorithmException allowedFailure) {
}
}
assertTrue("Test not performed", performed);
}
use of javax.crypto.EncryptedPrivateKeyInfo in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testGetEncoded02.
/**
* Test #2 for <code>getEncoded()</code> method <br>
* Assertion: returns the ASN.1 encoding of this object <br>
* Test preconditions: test object created using ctor which takes algorithm
* name and encrypted data as a parameters <br>
* Expected: equivalent encoded form (without alg params) must be returned
*
* @throws IOException
*/
public final void testGetEncoded02() throws IOException {
boolean performed = false;
for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
try {
EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfoData.algName0[i][0], EncryptedPrivateKeyInfoData.encryptedData);
// check that method under test returns
// valid encoded form
byte[] refEnc = EncryptedPrivateKeyInfoData.getValidEncryptedPrivateKeyInfoEncoding(EncryptedPrivateKeyInfoData.algName0[i][0], false);
// System.out.println(Array.toString(refEnc, " "));
byte[] actEnc = epki.getEncoded();
// System.out.println(Array.toString(actEnc, " "));
assertTrue(Arrays.equals(refEnc, actEnc));
performed = true;
} catch (NoSuchAlgorithmException allowedFailure) {
}
}
assertTrue("Test not performed", performed);
}
use of javax.crypto.EncryptedPrivateKeyInfo in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testGetKeySpecKeyProvider01.
public final void testGetKeySpecKeyProvider01() throws Exception {
boolean performed = false;
for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
try {
EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfoData.algName0[i][0], EncryptedPrivateKeyInfoData.encryptedData);
try {
// check that method under test throws NPE
epki.getKeySpec((Key) null, (Provider) null);
fail(getName() + "NullPointerException has not been thrown");
} catch (NullPointerException ok) {
}
try {
// check that method under test throws NPE
epki.getKeySpec(new Key() {
public String getAlgorithm() {
return "alg";
}
public String getFormat() {
return "fmt";
}
public byte[] getEncoded() {
return new byte[] {};
}
}, (Provider) null);
fail(getName() + "NullPointerException has not been thrown");
} catch (NullPointerException ok) {
}
performed = true;
} catch (NoSuchAlgorithmException allowedFailure) {
}
}
assertTrue("Test not performed", performed);
}
use of javax.crypto.EncryptedPrivateKeyInfo in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray3.
/**
* Test #3 for
* <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[])
* </code>
* constructor <br>
* Assertion: <code>IllegalArgumentException</code>- if encrypted data is
* empty, i.e. 0-length <br>
* Test preconditions: pass empty encrypted data <br>
* Expected: <code>IllegalArgumentException</code>
*
* @throws NoSuchAlgorithmException
* @throws IOException
*/
public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray3() throws Exception {
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance("DSA");
// use pregenerated AlgorithmParameters encodings
ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding("DSA"));
new EncryptedPrivateKeyInfo(ap, new byte[] {});
fail(getName() + ": IllegalArgumentException has not been thrown");
} catch (IllegalArgumentException ok) {
}
}
use of javax.crypto.EncryptedPrivateKeyInfo in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method test_ROUNDTRIP_GetKeySpecKeyProvider01.
/**
* Encrypted data contains valid PKCS8 key info encoding
*/
public final void test_ROUNDTRIP_GetKeySpecKeyProvider01() {
boolean performed = false;
for (int i = 0; i < algName.length; i++) {
for (int l = 0; l < provider.length; l++) {
if (provider[l] == null) {
continue;
}
TestDataGenerator g;
try {
// generate test data
g = new TestDataGenerator(algName[i][0], algName[i][1], privateKeyInfo, provider[l]);
} catch (TestDataGenerator.AllowedFailure allowedFailure) {
continue;
}
try {
// create test object
EncryptedPrivateKeyInfo epki;
if (g.ap() == null) {
epki = new EncryptedPrivateKeyInfo(algName[i][0], g.ct());
} else {
epki = new EncryptedPrivateKeyInfo(g.ap(), g.ct());
}
try {
PKCS8EncodedKeySpec eks = epki.getKeySpec(g.pubK() == null ? g.k() : g.pubK(), provider[l]);
if (!Arrays.equals(privateKeyInfo, eks.getEncoded())) {
fail(algName[i][0] + " != " + algName[i][1]);
}
} catch (InvalidKeyException e) {
fail(algName[i][0] + ", " + algName[i][1] + ": " + e);
}
performed = true;
} catch (NoSuchAlgorithmException allowedFailure) {
}
}
}
assertTrue("Test not performed", performed);
}
Aggregations