String macOid = macAlg.getObjectId().getId();
byte[] protectedBytes = ret.getProtectedBytes();
Mac mac = Mac.getInstance(macOid, "BC");
SecretKey key = new SecretKeySpec(basekey, macOid);
mac.init(key);
mac.reset();
mac.update(protectedBytes, 0, protectedBytes.length);
byte[] out = mac.doFinal();
DERBitString bs = new DERBitString(out);
// Finally store the protection bytes in the msg