}
protected PKIMessage protectPKIMessage(PKIMessage msg, boolean badObjectId, String password, String keyId, int iterations) throws NoSuchAlgorithmException,
NoSuchProviderException, InvalidKeyException {
// Create the PasswordBased protection of the message
PKIHeader head = msg.getHeader();
head.setSenderKID(new DEROctetString(keyId.getBytes()));
// SHA1
AlgorithmIdentifier owfAlg = new AlgorithmIdentifier("1.3.14.3.2.26");
// 567 iterations
int iterationCount = iterations;
DERInteger iteration = new DERInteger(iterationCount);
// HMAC/SHA1
AlgorithmIdentifier macAlg = new AlgorithmIdentifier("1.2.840.113549.2.7");
byte[] salt = "foo123".getBytes();
DEROctetString derSalt = new DEROctetString(salt);
// Create the new protected return message
String objectId = "1.2.840.113533.7.66.13";
if (badObjectId) {
objectId += ".7";
}
PBMParameter pp = new PBMParameter(derSalt, owfAlg, iteration, macAlg);
AlgorithmIdentifier pAlg = new AlgorithmIdentifier(new DERObjectIdentifier(objectId), pp);
head.setProtectionAlg(pAlg);
PKIBody body = msg.getBody();
PKIMessage ret = new PKIMessage(head, body);
// Calculate the protection bits
byte[] raSecret = password.getBytes();