}
public TestResult perform()
{
char[] password = { 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' };
PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();
ByteArrayInputStream bIn = new ByteArrayInputStream(sample);
ASN1InputStream dIn = new ASN1InputStream(bIn);
EncryptedPrivateKeyInfo info;
try
{
info = new EncryptedPrivateKeyInfo((ASN1Sequence)dIn.readObject());
}
catch (Exception e)
{
return new SimpleTestResult(false, getName() + ": failed construction - exception " + e.toString());
}
PBES2Parameters alg = new PBES2Parameters((ASN1Sequence)info.getEncryptionAlgorithm().getParameters());
PBKDF2Params func = PBKDF2Params.getInstance(alg.getKeyDerivationFunc().getParameters());
EncryptionScheme scheme = alg.getEncryptionScheme();
if (func.getKeyLength() != null)
{
keySize = func.getKeyLength().intValue() * 8;
}
int iterationCount = func.getIterationCount().intValue();
byte[] salt = func.getSalt();
generator.init(
PBEParametersGenerator.PKCS5PasswordToBytes(password),
salt,
iterationCount);
CipherParameters param;
if (scheme.getObjectId().equals(RC2_CBC))
{
RC2CBCParameter rc2Params = new RC2CBCParameter((ASN1Sequence)scheme.getObject());
byte[] iv = rc2Params.getIV();
param = new ParametersWithIV(generator.generateDerivedParameters(keySize), iv);
}
else
{
byte[] iv = ((ASN1OctetString)scheme.getObject()).getOctets();
param = new ParametersWithIV(generator.generateDerivedParameters(keySize), iv);
}
cipher.init(false, param);
byte[] data = info.getEncryptedData();