[英]Read RSAPublicKey in Java from XML file
如何從xml文件中讀取Java中的RSA公鑰?
這是文件格式。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<RSAKeyValue>
<Modulus>jWa96uXeSM6hUH0E/ueihtuowdte8</Modulus>
<Exponent>BAAQ</Exponent>
</RSAKeyValue>
此元素是XMLSec的一部分,通常它包含在<KeyInfo>中。 Java 6帶有XMLSec支持,但我懷疑它有解析這個單獨元素的公共接口。
這只是Base64編碼的公鑰。 比如說Base64將XML內容解碼為字節數組, modBytes
為modBytes
和expBytes
。 你可以把它轉換成這樣的JCE密鑰,
KeyFactory rsaFactory = KeyFactory.getInstance("RSA");
RSAPublicKeySpec rsaKeyspec =
new RSAPublicKeySpec(new BigInteger(modBytes),
new BigInteger(expBytes));
PublicKey key = rsaFactory.generatePublic(rsaKeyspec);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.