将模数和指数从 VB.Net 设置为 Android/Java [英] set Modulus and Exponent from VB.Net to Android/Java
问题描述
我有这个 RSA 公钥
,它是在我的服务器 VB.Net
中生成的.
I have this RSA public key
which is generated in VB.Net
my server.
<代码>< RSAKeyValue><模量> tv0tzng4pW7erDo2ke/Ku9TGKRukAzx + lihZVblIOE6GWIoiwlILOANeVliZLi1s5qMsXEUA4GV2woC1zFdhJvfFja8Nacl4I3CJ4JYmGqcSZinWKgo3MJdoEqFl9NliF4wTYLow3GYoUh03WxoeArozV1S03drP898b9PdbjPY + ji4jpZHJWnbfg + qWSziF1Q/pSAxpzabeoamz1 + ekqlhuxZavQUl + hIhx/quHqy3ybFWcX6yE5NKeY1fzX3L7</模量><指数>AQAB</指数></RSAKeyValue>
我想将此值设置为我的 android RSA 公钥,但使用此代码进行转换并未正确设置密钥.
I want to set this value to my android RSA public key but converting with this code doesn't set the key right.
<代码> RSAPublicKeySpec规范=新RSAPublicKeySpec(新的BigInteger( tv0tzng4pW7erDo2ke/Ku9TGKRukAzx + lihZVblIOE6GWIoiwlILOANeVliZLi1s5qMsXEUA4GV2woC1zFdhJvfFja8Nacl4I3CJ4JYmGqcSZinWKgo3MJdoEqFl9NliF4wTYLow3GYoUh03WxoeArozV1S03drP898b9PdbjPY + ji4jpZHJWnbfg + qWSziF1Q/pSAxpzabeoamz1 + ekqlhuxZavQUl + hIhx/quHqy3ybFWcX6yE5NKeY1fzX3L7" .getBytes()),new BigInteger("AQAB".getBytes()));
我也尝试过这段代码,但没有运气.
I tried this code too with no luck.
推荐答案
首先,您必须解码来自 Base64 的模数和指数.
First, you have to decode the modulus and the exponent from Base64.
其次,您必须为 BigInteger
使用不同的构造函数:
Second, you have to use a different constructor for BigInteger
:
BigInteger(int signum, byte[] magnitude)
与 signum
为一,因为这两个值都不是 2-complement 表示法并且总是正数.
with signum
as one, because the both values are not in 2-complement notation and are always positive.
这篇关于将模数和指数从 VB.Net 设置为 Android/Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!