I am trying to read a pfx certificate using Java from weblogic server but I am getting java.io.IOException: toDerInputStream rejects tag type 77
I am trying to read a pfx certificate using Java from weblogic server but I am getting java.io.IOException: toDerInputStream rejects tag type 77
It looks like you might be trying to use a .cer certificate where it should be .pfx or other format different of .cer. Check the KeyStore you are using or your certificate format.
String strFile = "certificate.cer"; // << ((( should be .pfx )))
File file = new File(strFile);
byte[] certificateBytes = FileUtils.readFileToByteArray(file);
String password = "MyPassword123";
KeyStore keyStore = KeyStore.getInstance("PKCS12"); // << KeyStore used for .pfx
try (ByteArrayInputStream bs = new ByteArrayInputStream(certificateBytes)) {
keyStore.load(bs, password.toCharArray());
} catch (NoSuchAlgorithmException | CertificateException e) {
e.printStackTrace();
}
this is for me.
as I download as base64 in string.
and my code need it in byte[],
and my code tells me "java.io.IOException: toDerInputStream rejects tag type 77".
then I do this in powershell,it works.
$fileContentBytes = get-content "the file you read from web"
$a= [System.Convert]::FromBase64String($fileContentBytes)
[IO.File]::WriteAllBytes(‘xxx.pfx’, $a)