使用 Bouncy Castle 获取 RSA Public key Remainder

Obtaining the RSA Public key Remainder using Bouncy Castle

我是密码学的新手,我想知道是否有任何已经实现的方法来获取 Public 密钥余数。

我发现了以下关于 public 余数的陈述: Issuer Public Key Modulus分为 两部分,一部分由 N 加州 – 36 个最高有效字节 模数(发行人最左边的数字 Public 密钥)和第二部分 由剩余的 N 我 − (N 加州 – 36) 模数的最低有效字节 (the Issuer Public Key Remainder)

在本书中: http://mech.vub.ac.be/teaching/info/mechatronica/finished_projects_2007/Groep%201/Smartcard_files/EMV%20v4.1%20Book%202.pdf

我正在使用 org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters#getModulus

获取模数部分。

我可以使用 Bouncy Castle 获得 public 密钥余数还是应该根据上述规范手动计算它?

不,BouncyCastle 不提供 API 来获取 public 密钥余数,因为 BouncyCastle 提供了 RSA 的一般实现,相反,public 密钥余数不常使用:主要仅供集成电路卡及相关软件使用。

所以,如果你需要求余数,你必须自己计算。不做集成电路卡就不用担心余数了

现在,这是一种计算余数的方法(我们假设定义了 Ni 和 Nca):

BigInteger modulus = ...;
int nbytes = Ni − (Nca − 36);
BigInteger remainder = modulus.divideAndRemainder(BigInteger.valueOf(2).pow(8*nbytes))[1];