问题
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