use of javax.crypto.EncryptedPrivateKeyInfo in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testGetEncoded03.
/**
* Test #3 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 testGetEncoded03() 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 encoded form
assertTrue(Arrays.equals(EncryptedPrivateKeyInfoData.getValidEncryptedPrivateKeyInfoEncoding(EncryptedPrivateKeyInfoData.algName0[i][0]), epki.getEncoded()));
performed = true;
} catch (NoSuchAlgorithmException allowedFailure) {
}
}
assertTrue("Test not performed", performed);
}
use of javax.crypto.EncryptedPrivateKeyInfo in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method test_ROUNDTRIP_GetKeySpecCipher01.
/**
* Encrypted data contains valid PKCS8 key info encoding
*/
public final void test_ROUNDTRIP_GetKeySpecCipher01() {
boolean performed = false;
for (int i = 0; i < algName.length; i++) {
try {
// generate test data
TestDataGenerator g = new TestDataGenerator(algName[i][0], algName[i][1], privateKeyInfo, null);
// 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());
}
// call methods under test
try {
PKCS8EncodedKeySpec eks = epki.getKeySpec(g.c());
if (!Arrays.equals(privateKeyInfo, eks.getEncoded())) {
fail(algName[i][0] + " != " + algName[i][1]);
}
} catch (InvalidKeySpecException e) {
fail(algName[i][0] + ", " + algName[i][1] + e + "\n");
}
performed = true;
} catch (TestDataGenerator.AllowedFailure allowedFailure) {
} catch (NoSuchAlgorithmException allowed) {
}
}
assertTrue("Test not performed", performed);
}
use of javax.crypto.EncryptedPrivateKeyInfo in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testGetEncryptedData04.
/**
* Test #4 for <code>getEncryptedData()</code> method <br>
* Assertion: returns a new array each time this method is called <br>
* Test preconditions: test object created using ctor which takes algorithm
* name and encrypted data as a parameters <br>
* Expected: refs to encrypted data byte array passed to the ctor and
* returned by the method under test must be different
*/
public final void testGetEncryptedData04() {
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
// new array each time
byte[] ecd1 = epki.getEncryptedData();
byte[] ecd2 = epki.getEncryptedData();
assertNotSame(EncryptedPrivateKeyInfoData.encryptedData, ecd1);
assertNotSame(EncryptedPrivateKeyInfoData.encryptedData, ecd2);
assertNotSame(ecd1, ecd2);
performed = true;
} catch (NoSuchAlgorithmException allowedFailure) {
}
}
assertTrue("Test not performed", performed);
}
use of javax.crypto.EncryptedPrivateKeyInfo in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testGetEncoded04.
/**
* Test #4 for <code>getEncoded()</code> method <br>
* Assertion: returns a new array each time this method is called <br>
* Test preconditions: test object created using ctor which takes algorithm
* name and encrypted data as a parameters <br>
* Expected: several refs to byte array returned by the method under test
* must be different
*
* @throws IOException
*/
public final void testGetEncoded04() 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
// new array each time
byte[] ec1 = epki.getEncoded();
byte[] ec2 = epki.getEncoded();
byte[] ec3 = epki.getEncoded();
assertNotSame(ec1, ec2);
assertNotSame(ec2, ec3);
assertNotSame(ec1, ec3);
performed = true;
} catch (NoSuchAlgorithmException allowedFailure) {
}
}
assertTrue("Test not performed", performed);
}
use of javax.crypto.EncryptedPrivateKeyInfo in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testGetKeySpecKeyString01.
public final void testGetKeySpecKeyString01() 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, "SomeProviderName");
fail(getName() + "NullPointerException has not been thrown");
} catch (NullPointerException ok) {
}
try {
epki.getKeySpec(new Key() {
public String getAlgorithm() {
return "alg";
}
public String getFormat() {
return "fmt";
}
public byte[] getEncoded() {
return new byte[] {};
}
}, "StrangeProviderName");
fail(getName() + "NoSuchProviderException has not been thrown");
} catch (NoSuchProviderException ok) {
//expected
}
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[] {};
}
}, (String) null);
fail(getName() + "NullPointerException has not been thrown");
} catch (NullPointerException ok) {
}
performed = true;
} catch (NoSuchAlgorithmException allowedFailure) {
}
}
assertTrue("Test not performed", performed);
}
Aggregations