我们正在尝试创建一个 RSA 公钥,它应该是八位字节字符串,然后我们需要对其进行 DER 编码。
我们正在尝试使用以下代码创建 key 对:
public static KeyPair getRSAKeyPair() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException {
KeyPairGenerator g = KeyPairGenerator.getInstance("RSA", "SC");
g.initialize(2048);
return g.generateKeyPair();
}
然后使用下面的代码从中获取公钥
PublicKey publicKey1 = keyPair.getPublic();
byte[] pubkey = publicKey1.getEncoded();
上面代码中获取的公钥似乎是 DER 编码的二进制字符串。
查询:
- 如何更改上述代码,以便它创建一个八位字节字符串。
- 如何对其进行 DER 编码。
最佳答案
它是一个八位字节字符串; “八位字节字符串”是“字节数组”的另一个术语。
并且它已经是 DER 编码的,因为 getEncoded
通常返回 DER 编码 SubjectPublicKeyInfo
。试试openssl asn1parse -inform DER -in <file>
就在上面。
关于java - DER 编码的 RSA 公钥(八位字节字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40911825/