HDDS-1075. Fix CertificateUtil#parseRSAPublicKey charsetName. Contributed by Siddharth Wagle.
This commit is contained in:
parent
5c10630ad8
commit
ca4e46a05e
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.security.cert.CertificateFactory;
|
import java.security.cert.CertificateFactory;
|
||||||
@ -45,7 +46,7 @@ public static RSAPublicKey parseRSAPublicKey(String pem) throws ServletException
|
|||||||
try {
|
try {
|
||||||
CertificateFactory fact = CertificateFactory.getInstance("X.509");
|
CertificateFactory fact = CertificateFactory.getInstance("X.509");
|
||||||
ByteArrayInputStream is = new ByteArrayInputStream(
|
ByteArrayInputStream is = new ByteArrayInputStream(
|
||||||
fullPem.getBytes("UTF8"));
|
fullPem.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
X509Certificate cer = (X509Certificate) fact.generateCertificate(is);
|
X509Certificate cer = (X509Certificate) fact.generateCertificate(is);
|
||||||
key = cer.getPublicKey();
|
key = cer.getPublicKey();
|
||||||
@ -58,8 +59,6 @@ public static RSAPublicKey parseRSAPublicKey(String pem) throws ServletException
|
|||||||
message = "CertificateException - PEM may be corrupt";
|
message = "CertificateException - PEM may be corrupt";
|
||||||
}
|
}
|
||||||
throw new ServletException(message, ce);
|
throw new ServletException(message, ce);
|
||||||
} catch (UnsupportedEncodingException uee) {
|
|
||||||
throw new ServletException(uee);
|
|
||||||
}
|
}
|
||||||
return (RSAPublicKey) key;
|
return (RSAPublicKey) key;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user