Proposing the getParams method in PublicKey and PrivateKey
Wei-Jun Wang
weijun.wang at oracle.com
Thu Oct 12 18:38:04 UTC 2023
Hi All,
Currently, every algorithm-specific asymmetric key interface (Ex: ECKey) in JDK has a getParams() method. We are thinking about duplicating this method in PublicKey and PrivateKey (returning null by default) so the method is available for all asymmetric keys. Once we have this method, even if a new algorithm is introduced in a future release, there is no need to rewrite your applications to use any new algorithm-specific API (suppose the new algorithm does not invent any new AlgorithmParameterSpec type).
Since PublicKey/PrivateKey and, say, ECKey do not have the same parent interface, there will be an ambiguity in their child interfaces to decide which getParams() to choose. In order to fix this, we will add new default methods in all existing child interfaces (Ex: ECPublicKey and ECPrivateKey) that return the same type as their algorithm-specific parent (Ex: ECKey::getParams returns ECParameterSpec) with a value null.
Do you have any comment?
The risk is that if an existing algorithm-specific interface already has this method but does not return an AlgorithmParameterSpec object there will be a conflict. In fact, inside OpenJDK, DSAKey's getParams() returns a DSAParams object which is not an AlgorithmParameterSpec. We'll modify it to extend AlgorithmParameterSpec.
If there is something similar in your code, please let us know. And, do you think you can fix it the same way we do?
Thanks,
Weijun
----
Example:
java.security.PublicKey:
+ default AlgorithmParameterSpec getParams(){
+ return null;
+ }
java.security.interfaces.ECKey:
ECParameterSpec getParams();
java.security.interfaces.ECPublicKey:
+ default ECParameterSpec getParams(){
+ return null;
+ }
More information about the security-dev
mailing list