我从.NET系统的XML格式的私钥和公钥。我必须使用这些密钥来执行Java中的加密/解密。有什么办法可以做到吗?移植的.Net RSA 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私钥来解密数据?
能否请你也分享你的工作样本?我被困在一个非常类似的问题,并没有找到关于它的网络。 – c0d3Junk13 2013-02-20 21:01:33
你用什么来解析XML? – ecem 2013-03-26 15:30:20
好吧,我觉得这是JDOM,我不应该使用Google之前问的事情。 – ecem 2013-03-26 15:35:41