java.security.Key.getEncoded() 返回 DER 编码格式的数据吗?
Do java.security.Key.getEncoded() returns data in DER encoded format?
If not, is there a method that do?
UPDATE: A Key interface holding an RSA private key implementation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
取决于密钥的类型。大多数对称密钥返回没有编码的原始字节。大多数公钥使用 ASN.1/DER 编码。
您不应该关心密钥是如何编码的。将 getEncoded 视为序列化函数。它返回密钥的字节流表示形式,可以保存该字节流并稍后将其转换回密钥。
对于 RSA 私钥,它可能被编码为 PKCS#1 或 PKCS#8。 PKCS#1 是首选编码,因为它包含额外的 CRT 参数,可以加速私钥操作。
Sun JCE 始终以 PKCS#1 编码生成密钥对,因此私钥始终以 PKCS#1 中定义的格式进行编码,
Depending on the type of key. Most symmetric keys return raw bytes with no encoding. Most public keys uses ASN.1/DER encoding.
You shouldn't care about how the key is encoded. Treat getEncoded as serialization function. It returns byte-stream representation of the key, which can be saved and converted back into the key later.
For RSA private keys, it's may be encoded as PKCS#1 or PKCS#8. PKCS#1 is the preferred encoding because it contains extra CRT parameters which speed up private key operations.
Sun JCE always generates key pairs in PKCS#1 encoding so the private key is always encoded in this format defined in PKCS#1,