set Modulus and Exponent from VB.Net to Android/Java

£可爱£侵袭症+ 提交于 2019-12-25 09:16:02

问题


I have this RSA public key which is generated in VB.Net my server.

<RSAKeyValue><Modulus>tv0tzng4pW7erDo2ke/Ku9TGKRukAzx+lihZVblIOE6GWIoiwlILOANeVliZLi1s5qMsXEUA4GV2woC1zFdhJvfFja8Nacl4I3CJ4JYmGqcSZinWKgo3MJdoEqFl9NliF4wTYLow3GYoUh03WxoeArozV1S03drP898b9PdbjPY+ji4jpZHJWnbfg+qWSziF1Q/pSAxpzabeoamz1+ekqlhuxZavQUl+hIhx/quHqy3ybFWcX6yE5NKeY1fzX3L7</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>

I want to set this value to my android RSA public key but converting with this code doesn't set the key right.

RSAPublicKeySpec spec = new RSAPublicKeySpec(new BigInteger("tv0tzng4pW7erDo2ke/Ku9TGKRukAzx+lihZVblIOE6GWIoiwlILOANeVliZLi1s5qMsXEUA4GV2woC1zFdhJvfFja8Nacl4I3CJ4JYmGqcSZinWKgo3MJdoEqFl9NliF4wTYLow3GYoUh03WxoeArozV1S03drP898b9PdbjPY+ji4jpZHJWnbfg+qWSziF1Q/pSAxpzabeoamz1+ekqlhuxZavQUl+hIhx/quHqy3ybFWcX6yE5NKeY1fzX3L7".getBytes())
,new BigInteger("AQAB".getBytes()));

EDIT: I tried this code too with no luck.


回答1:


First, you have to decode the modulus and the exponent from Base64.

Second, you have to use a different constructor for BigInteger:

BigInteger(int signum, byte[] magnitude)

with signum as one, because the both values are not in 2-complement notation and are always positive.



来源:https://stackoverflow.com/questions/42735451/set-modulus-and-exponent-from-vb-net-to-android-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!