Skip to content

Commit

Permalink
added provision for default setting of digest calculator provider to …
Browse files Browse the repository at this point in the history
…the JcePBEDataDecryptorFactoryBuilder
  • Loading branch information
dghgit committed Feb 12, 2020
1 parent 34bb276 commit b62d7fb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public JcaPGPDigestCalculatorProviderBuilder()
{
}

JcaPGPDigestCalculatorProviderBuilder(OperatorHelper helper)
{
this.helper = helper;
}

/**
* Sets the provider to use to obtain cryptographic primitives.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public class JcePBEDataDecryptorFactoryBuilder
private OperatorHelper helper = new OperatorHelper(new DefaultJcaJceHelper());
private PGPDigestCalculatorProvider calculatorProvider;

/**
* Base constructor - assume the required digest calculators can be provided from the same source as
* the cipher needed.
*/
public JcePBEDataDecryptorFactoryBuilder()
{
this.calculatorProvider = null;
}

/**
* Base constructor.
*
Expand Down Expand Up @@ -68,6 +77,17 @@ public JcePBEDataDecryptorFactoryBuilder setProvider(String providerName)
*/
public PBEDataDecryptorFactory build(char[] passPhrase)
{
if (calculatorProvider == null)
{
try
{
calculatorProvider = new JcaPGPDigestCalculatorProviderBuilder(helper).build();
}
catch (PGPException e)
{
throw new IllegalStateException("digest calculator provider cannot be built with current helper: " + e.getMessage());
}
}
return new PBEDataDecryptorFactory(passPhrase, calculatorProvider)
{
public byte[] recoverSessionData(int keyAlgorithm, byte[] key, byte[] secKeyData)
Expand Down

0 comments on commit b62d7fb

Please sign in to comment.