Obtaining the RSA Public key Remainder using Bouncy Castle

874 Views Asked by At

I am new to cryptography and I was wondering if there is any already implemented method to get the Public Key remainder.

I found the following statement about the public remainder: the Issuer Public Key Modulus is divided into two parts, one part consisting of the N CA – 36 most significant bytes of the modulus (the Leftmost Digits of the Issuer Public Key) and a second part consisting of the remaining N I − (N CA – 36) least significant bytes of the modulus (the Issuer Public Key Remainder)

in this book: http://mech.vub.ac.be/teaching/info/mechatronica/finished_projects_2007/Groep%201/Smartcard_files/EMV%20v4.1%20Book%202.pdf

and I am using org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters#getModulus

to get the modulus part.

Can I obtain the public key remainder using Bouncy Castle or should I compute it manually based on the above specification?

1

There are 1 best solutions below

0
On BEST ANSWER

No, BouncyCastle does not offer an API to get the public key remainder, because BouncyCastle offers a general implementation of RSA and, on the contrary, the public key remainder is not often used: it is mainly used only by Integrated Circuit Cards and associated software.

So, if you need to get the remainder, you must compute it yourself. You should not worry about the remainder if you do not deal with Integrated Circuit Cards.

Now, here is a way to compute the remainder (we suppose Ni and Nca are defined):

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