【发布时间】:2018-02-02 22:56:08
【问题描述】:
我的服务器端(C# 或 .Net)人员给了我一个 xml 格式的 RSA 密钥对,但问题是我无法在我的 Java/Android 中使用给定的密钥 代码,它总是抛出 InValidKeySpec 异常。
我以某种方式管理 RSAPublic 密钥转换为 Java 可理解的 RSAPublic 密钥格式 -
String Modoutput = "pgFkNu7tN3K8VCxxvKMFwqaRJ6I158/aihg1J1p13P5HvVz8Pn2oC7hfdhujlQxHPsV/b8Rc3Snq5KGmC4VBnw==";
String Expoutput = "AQAB";
byte[] exponentBytes = Base64.decode(Expoutput);
byte[] modulusBytes = Base64.decode(Modoutput);
BigInteger e = new BigInteger(1, exponentBytes);
BigInteger m = new BigInteger(1, modulusBytes);
RSAPublicKeySpec keySpec = new RSAPublicKeySpec(m, e);
PublicKey mServerPublicKey = rsaKeyFactory.generatePublic(keySpec);
但无法将给定的 RSAPrivate (C#) 密钥转换为可理解的 Java/Android。 我试过这个link 和this
我正在研究这个,但没有成功,需要专家的帮助。
编码愉快 :-)
【问题讨论】: