如何解决将字节数组更改为 PKCS12 证书的私钥
我从 Azure Key Vault 获取我的证书凭据并使用来自 url 的值:"sid": "https://.vault.azure.net/secrets/ 但是我遇到了这个错误 xml: 有人可以帮我吗?package com.test;
import org.apache.commons.codec.binary.Base64;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Arrays;
public class decodeBase64 {
public static PrivateKey main(String key) throws InvalidKeySpecException,NoSuchAlgorithmException {
String string = key;
// Get bytes from string
byte[] byteArray = Base64.decodeBase64(string.getBytes());
// Print the decoded array
System.out.println(Arrays.toString(byteArray));
// Print the decoded string
//String decodedString = new String(byteArray);
KeyFactory kf = KeyFactory.getInstance("RSA"); // or "EC" or whatever
PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(byteArray));
//System.out.println(decodedString);
return privateKey;
}
private static PrivateKey generatePrivate(PKCS8EncodedKeySpec pkcs8EncodedKeySpec) {
// TODO Auto-generated method stub
return null;
}
}
"Invocation of static Method 'main(java.lang.String)' from Class 'com.test.decodeBase64' with arguments [java.lang.String key] resulted in an error.
Expected arguments are [java.lang.String key].
Cause: java.security.spec.InvalidKeySpecException - java.security.InvalidKeyException: IOException : version mismatch: (supported: 00,parsed: 03"
`<sub-flow name="encode" doc:id="b260143f-be3c-4f65-be18-49eff95b834d" >
<java:invoke-static doc:name="Invoke static" doc:id="996b6d31-9b1d-4f34-ae64-790f37fd1996" class="com.test.decodeBase64" method="main(java.lang.String)" target="content">
<java:args ><![CDATA[#[{key: <*my certificates sid value in String*>}]]]></java:args>
</java:invoke-static>
<logger level="INFO" doc:name="Logger" doc:id="041a9e19-8e4b-4b7c-a0b6-e2f3672b89d4" message="#[payload]"/>
</sub-flow>`
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。