8205720: KeyFactory#getKeySpec and translateKey thorws NullPointerException with Invalid key

Updated SunRsaSign provider to check and throw InvalidKeyException for null key algo/format/encoding

Reviewed-by: xuelei
This commit is contained in:
Valerie Peng 2018-06-30 00:33:05 +00:00
parent 11184615a8
commit ecc5979769
4 changed files with 33 additions and 21 deletions

View file

@ -116,6 +116,9 @@ public final class RSAPublicKeyImpl extends X509Key implements RSAPublicKey {
* Construct a key from its encoding. Used by RSAKeyFactory.
*/
RSAPublicKeyImpl(byte[] encoded) throws InvalidKeyException {
if (encoded == null || encoded.length == 0) {
throw new InvalidKeyException("Missing key encoding");
}
decode(encoded); // this sets n and e value
RSAKeyFactory.checkRSAProviderKeyLengths(n.bitLength(), e);
checkExponentRange(n, e);