java - DER 编码的 RSA 公钥(八位字节字符串)

标签 java android rsa der

我们正在尝试创建一个 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 编码的二进制字符串。

查询:

  1. 如何更改上述代码,以便它创建一个八位字节字符串。
  2. 如何对其进行 DER 编码。

最佳答案

一个八位字节字符串; “八位字节字符串”是“字节数组”的另一个术语。

并且它已经是 DER 编码的,因为 getEncoded通常返回 DER 编码 SubjectPublicKeyInfo 。试试openssl asn1parse -inform DER -in <file>就在上面。

关于java - DER 编码的 RSA 公钥(八位字节字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40911825/

相关文章:

java - 收集多维数组的列来设置

android - 在Android中左右对齐两个按钮布局

android - 在真正的 android 设备 2.3 上的 google maps v2 中膨胀类 fragment ?

java - 无法加载 RSA 公钥

c# - 要解密的数据超出了该模数的最大值 36 字节

node.js - node-forge 如何从文件中读取私有(private) rsa key

javascript - Android 网页 View 像素

java - 在 MotionEvent.ACTION_MOVE 上重绘 View

java - 从服务器端代码访问受安全约束保护的 servlet

android - Safetynet 问题状态 {statusCode=NETWORK_ERROR, resolution=null}