throws IOException, ASN1Exception, GeneralSecurityException {
// byte[] encodedData;
ByteArrayInputStream bais;
PBEKeySpec pbeSpec = null;
byte[] data = null;
EncryptedData encData = null;
if (((ContentInfo) this.get(i)).getContent() instanceof EncryptedData) {
encData = (EncryptedData) ((ContentInfo) this.get(i)).getContent();
} else {
System.out
.println("This bag is public-key protected or not protected at all.");
return null;
}
// "PbeWithSHAAnd40BitRC2_CBC";
String algName = encData.getAlgorithm();
// Create the PBEBMPKey ;
pbeSpec = new PBEKeySpec(passwd);
SecretKeyFactory skf = null;
skf = SecretKeyFactory.getInstance(algName);
SecretKey pbeKey = skf.generateSecret(pbeSpec);
encData.init(pbeKey);
data = encData.getData();
bais = new ByteArrayInputStream(data);
SafeContents safe = new SafeContents();
BERDecoder decoder = new BERDecoder(bais);
safe.decode(decoder);
bais.close();