79092480

Date: 2024-10-16 04:42:37
Score: 1.5
Natty:
Report link

Ok - I found a workaround - create two AlgorithmParameters one with the correct name, and one with the correct body; then init the first one with the body from the 2nd one. Yes, this is really nasty...

Any better way?

/* right name, wrong body; don't init yet
 * PBEParamterSpec does not have enough information to initialize this
 * object: cipher OID and kdf OID will be missing
 */
AlgorithmParameters realParams = AlgorithmParameters.getInstance("PBES2");


/* wrong name, right body; do initialize
 * the provider initializes everything incl. cipher OID
 * kdf OID, but stores an incorrect String algorithm 
 */
AlgorithmParameters tempParams = AlgorithmParameters.getInstance("PBEWithHmacSHA256AndAES_256");

PBEParameterSpec pbeSpec = new PBEParameterSpec(salt, iterationCount, ivSpec);
tempParams.init(pbeSpec);

/*... invasion of the body snatchers  ... initialize with the
correct body */

realParams.init(tempParams.getEncoded());

new EncryptedPrivateKeyInfo(realParams, encryptedData); // profit!!
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Anthony Alba