HDDS-1075. Fix CertificateUtil#parseRSAPublicKey charsetName. Contributed by Siddharth Wagle.

This commit is contained in:
Xiaoyu Yao 2019-02-11 12:00:36 -08:00
parent 5c10630ad8
commit ca4e46a05e

View File

@ -19,6 +19,7 @@
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.PublicKey;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
@ -45,7 +46,7 @@ public static RSAPublicKey parseRSAPublicKey(String pem) throws ServletException
try {
CertificateFactory fact = CertificateFactory.getInstance("X.509");
ByteArrayInputStream is = new ByteArrayInputStream(
fullPem.getBytes("UTF8"));
fullPem.getBytes(StandardCharsets.UTF_8));
X509Certificate cer = (X509Certificate) fact.generateCertificate(is);
key = cer.getPublicKey();
@ -58,8 +59,6 @@ public static RSAPublicKey parseRSAPublicKey(String pem) throws ServletException
message = "CertificateException - PEM may be corrupt";
}
throw new ServletException(message, ce);
} catch (UnsupportedEncodingException uee) {
throw new ServletException(uee);
}
return (RSAPublicKey) key;
}