将 .Net RSA xml 密钥移植到 Java
2022-09-02 01:00:56
						我有来自.Net系统的xml格式的私钥和公钥。我必须使用此密钥在Java中执行加密/解密。有什么办法可以做到这一点吗?
公钥看起来像这样:
<RSAKeyValue>
    <Modulus>jHIxcGzzpByFv...pvhxFnP0ssmlBfMALis</Modulus>
    <Exponent>AQAB</Exponent>
</RSAKeyValue>
私钥:
<RSAKeyValue>
    <Modulus>4hjg1ibWXHIlH...ssmlBfMAListzrgk=</Modulus>
    <Exponent>AQAB</Exponent>
    <P>8QZCtrmJcr9uW7VRex+diH...jLHV5StmuBs1+vZZAQ==</P>
    <Q>8CUvJTv...yeDszMWNCQ==</Q>
    <DP>elh2Nv...cygE3657AQ==</DP>
    <DQ>MBUh5XC...+PfiMfX0EQ==</DQ>
    <InverseQ>oxvsj4WCbQ....LyjggXg==</InverseQ>
    <D>KrhmqzAVasx...uxQ5VGZmZ6yOAE=</D>
</RSAKeyValue>
我已经写了一些代码来加密数据,但我不确定它是否正确。
        Element modulusElem = root.getChild("Modulus");
        Element exponentElem = root.getChild("Exponent");
        byte[] expBytes = decoder.decodeBuffer(exponentElem.getText().trim());
        byte[] modBytes = decoder.decodeBuffer(modulusElem.getText().trim());
        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(new BigInteger(1, modBytes), new BigInteger(1, expBytes));
        KeyFactory fact = KeyFactory.getInstance("RSA");
        PublicKey pubKey = fact.generatePublic(keySpec);
如何从xml创建私钥来解密数据?