added correct handling of AlgorithmParameters
import java.security.cert.X509Certificate;
import java.security.interfaces.ECPublicKey;
import java.security.spec.AlgorithmParameterSpec;
+import java.security.spec.InvalidParameterSpecException;
import java.security.spec.MGF1ParameterSpec;
import java.util.HashMap;
import java.util.HashSet;
@@ -101,6 +102,20 @@ public JceAsymmetricKeyWrapper(AlgorithmIdentifier algorithmIdentifier, PublicKe
this.publicKey = publicKey;
}
+ /**
+ * Create a wrapper, overriding the algorithm type that is stored in the public key.
+ *
+ * @param algorithmParams algorithm parameters for encryption algorithm to be used.
+ * @param publicKey the public key to be used.
+ */
+ public JceAsymmetricKeyWrapper(AlgorithmParameters algorithmParams, PublicKey publicKey)
+ throws InvalidParameterSpecException
+ {
+ super(extractFromSpec(algorithmParams.getParameterSpec(AlgorithmParameterSpec.class)));
+
+ this.publicKey = publicKey;
+ }
+
/**
* Create a wrapper, overriding the algorithm type that is stored in the public key.
*
@@ -136,19 +151,6 @@ public JceAsymmetricKeyWrapper setSecureRandom(SecureRandom random)
return this;
}
- /**
- * Provide a set of algorithm parameters for the key wrapper cipher to use.
- *
- * @param algorithmParameters algorithmParameters for key wrapper.
- * @return the current builder instance.
- */
- public JceAsymmetricKeyWrapper setAlgorithmParameters(AlgorithmParameters algorithmParameters)
- {
- this.algorithmParameters = algorithmParameters;
-
- return this;
- }
-
/**
* Internally algorithm ids are converted into cipher names using a lookup table. For some providers
* the standard lookup table won't work. Use this method to establish a specific mapping from an
