String providedCert = mc.getProperty("keycloakkey-x5c")+"";
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(providedCert);
String certstring1 = node.get(0).toString();
log.info("total "+ node.size()+ " certificate return from keycloak, taking the first cert: " + certstring1);
DecodedJWT jwt = JWT.decode(providedToken);
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey)getPublicKey(certstring1), null);
private static PublicKey getPublicKey(String CertString) throws NoSuchAlgorithmException, InvalidKeySpecException, Exception {
log.info("CertString received in getPublicKey(): " + CertString);
//sample CertString value = "MIIHFDCCBfygAwIBAgIIK2o4sL7KHQgwDQYJKoZIhvcNAQELBQAwSTELMAkGA1UEBhMCVVMxEzARBgNVBAoTCkdvb2dsZSBJbmMxJTAjBgNVBAMTHEdvb2dsZSBJbnRlcm5ldCBBdXRob3JpdHkgRzIwHhcNMTYxMjE1MTQwNDE1WhcNMTcwMzA5MTMzNTAwWjBmMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzETMBEGA1UECgwKR29vZ2xlIEluYzEVMBMGA1UEAwwMKi5nb29nbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEG1y99TYpFSSiawnjJKYI8hyEzJ4M+IELfLjmSsYI7fW/V8AT61quCswtBMikJYqzYBZrV2Reu5sHlLr6936cR6OCBKwwggSoMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjCCA2sGA1UdEQSCA2IwggNeggwqLmdvb2dsZS5jb22CDSouYW5kcm9pZC5jb22CFiouYXBwZW5naW5lLmdvb2dsZS5jb22CEiouY2xvdWQuZ29vZ2xlLmNvbYIWKi5nb29nbGUtYW5hbHl0aWNzLmNvbYILKi5nb29nbGUuY2GCCyouZ29vZ2xlLmNsgg4qLmdvb2dsZS5jby5pboIOKi5nb29nbGUuY28uanCCDiouZ29vZ2xlLmNvLnVrgg8qLmdvb2dsZS5jb20uYXKCDyouZ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bsjAMBgNVHRMBAf8EAjAAMB8GA1UdIwQYMBaAFErdBhYbvPZotXb1gba7Yhq6WoEvMCEGA1UdIAQaMBgwDAYKKwYBBAHWeQIFATAIBgZngQwBAgIwMAYDVR0fBCkwJzAloCOgIYYfaHR0cDovL3BraS5nb29nbGUuY29tL0dJQUcyLmNybDANBgkqhkiG9w0BAQsFAAOCAQEAWZQy0Kvn9cPnIh7Z4kfUCXX/dhdvjLJYFAn3b3d5DVs1BLYuukfIjilVdAeTUHZH7TLn/uVejg3yS0ssRg1ds1iv2O9DJbnl5FHcjNAvwfN533FulWP41OC6B6dC6BGGTXTvQobDup7/EKg1GWX9ksBtTfKLH5wrjhN955Itnd25Sjw2bSjLaWEtTrjINXmnBoc2+qHFzF/fNxK1KbmkBboUIGoaGsThe3AF0Ye+XAeaZH08+GdrorknlHDQLLtHIcJ3C6PrQ/kTpwWd/TVXW42BN+N7xZiGJbvKOg0S0rk2hzhgX4QoUKZHMqqh1sS6ypkfnWx75nh325y4Tenk+A==";
CertString= CertString.replace("\"", "");//remove beginning and ending double quote
//construct cert object from CertString
byte encodedCert[] = Base64.getDecoder().decode(CertString);
ByteArrayInputStream inputStream = new ByteArrayInputStream(encodedCert);
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate)certFactory.generateCertificate(inputStream);
if (cert != null) {
PublicKey pubKey = cert.getPublicKey();//use cert object to extract PublicKey object
log.info("PublicKey >>> " + pubKey.toString());
if (pubKey instanceof RSAPublicKey) {
return pubKey;
}else{
throw new Exception("Unexpetced Error, non-RSAPublicKey retrieved from keycloak certificate");
}
}else{
throw new Exception("Unexpetced Error during X509Certificate parsing from keycloak certificate string, decoded cert=null");
}
}
所以同样的代码在我的本地机器中使用Java8和Java11都很好,但在Docker容器中却失败了,所以我使用了getDecoder()
,我使用了getMimeDecoder()
所以以前的代码是
byte encodedCert[] = Base64.getDecoder().decode(CertString);
现在是
Base64.getMimeDecoder().decode(CertString);
问题内容: 我正在尝试在用户注册后发送确认电子邮件。我为此使用JavaMail库和Java 8 Base64 util类。 我以以下方式对用户电子邮件进行编码: 在哪里: 然后以这种方式在ConfirmRegistrationCommand中对此进行解码: 当我尝试解码时: 我正在。 我尝试使用基本的编码/解码器(而不是URL编码),但没有成功。 解决了: 问题是下一个-在该行中: 我在字节数组上
我正在尝试在用户注册后发送确认邮件。为此,我使用了JavaMail库和Java8 Base64 util类。 然后以如下方式在ConfirmRegistrationCommand中解码: 当我试图解码时: 我正在获取。 我尝试使用基本的编码/解码器(不是URL的)没有成功。 已解决:
它失败了并给出了像贝娄这样的例外。 xml格式与不兼容吗?
我正在通过Android应用程序发送byte[]作为编码字符串。我转换Byte[]的方式如下(基本上Byte[]是拇指扫描/指纹扫描图像):Android 这就是我在服务器端(Java)解码的方式: 它会生成以下异常: ]]ServletException.Java.lang.IllegalArgumentException的根本原因:非法的base64字符-1在Java.util.base64$
我正在做的:我试图在android中做一个反向地理编码 这一行给出了这个错误:: jsonFunctions.java
问题内容: 我得到:错误: 将Base64Image传递给时: 让我知道是否需要完整的base64,我刚刚粘贴了第一部分,因为问题似乎在4个字节之内? 你知道为什么吗? 问题答案: 并非您尝试解码的所有输入字符串都是Base64编码形式。 您所拥有的是一个Data URI方案 ,它提供了一种在网页中内联包含数据的方法,就好像它们是外部资源一样。 它具有以下格式: 在您的情况下,如果是MIME类型,